diff --git a/DESCRIPTION b/DESCRIPTION index b2a1b93..c5b5d20 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -27,7 +27,6 @@ Suggests: gridExtra, knitr, ragg, - reshape2, rmarkdown VignetteBuilder: knitr Encoding: UTF-8 diff --git a/NEWS.md b/NEWS.md index 5da2bfe..e475bdc 100644 --- a/NEWS.md +++ b/NEWS.md @@ -11,6 +11,8 @@ This change enhances package development transparency, reduces unnecessary indirection, and simplifies contributions by avoiding the construction of the palette data using the R script in `data-raw/` (#42). +- For continuous palette examples, remove the reshape2 dependency and + use more compact grid layout to reduce output image size (#45). # ggsci 3.1.0 diff --git a/R/continuous-gsea.R b/R/continuous-gsea.R index 446b639..933b17d 100644 --- a/R/continuous-gsea.R +++ b/R/continuous-gsea.R @@ -83,11 +83,14 @@ pal_gsea <- function(palette = c("default"), n = 12, alpha = 1, reverse = FALSE) #' #' @examples #' library("ggplot2") -#' library("reshape2") -#' data("mtcars") #' +#' data("mtcars") #' cor <- cor(mtcars) -#' cor_melt <- melt(cor) +#' cor_melt <- data.frame( +#' Var1 = rep(seq_len(nrow(cor)), times = ncol(cor)), +#' Var2 = rep(seq_len(ncol(cor)), each = nrow(cor)), +#' value = as.vector(cor) +#' ) #' #' ggplot( #' cor_melt, diff --git a/R/continuous-material.R b/R/continuous-material.R index bc8dab7..b11b677 100644 --- a/R/continuous-material.R +++ b/R/continuous-material.R @@ -113,11 +113,14 @@ pal_material <- function( #' #' @examples #' library("ggplot2") -#' library("reshape2") -#' data("mtcars") #' +#' data("mtcars") #' cor <- abs(cor(mtcars)) -#' cor_melt <- melt(cor) +#' cor_melt <- data.frame( +#' Var1 = rep(seq_len(nrow(cor)), times = ncol(cor)), +#' Var2 = rep(seq_len(ncol(cor)), each = nrow(cor)), +#' value = as.vector(cor) +#' ) #' #' ggplot( #' cor_melt, diff --git a/README.Rmd b/README.Rmd index 56d9087..4165837 100644 --- a/README.Rmd +++ b/README.Rmd @@ -279,11 +279,13 @@ grid.arrange(p1_frontiers, p2_frontiers, ncol = 2) ### GSEA ```{r} -library("reshape2") - data("mtcars") -cor <- cor(unname(cbind(mtcars, mtcars, mtcars, mtcars))) -cor_melt <- melt(cor) +cor <- cor(unname(mtcars)) +cor_melt <- data.frame( + Var1 = rep(seq_len(nrow(cor)), times = ncol(cor)), + Var2 = rep(seq_len(ncol(cor)), each = nrow(cor)), + value = as.vector(cor) +) p3 <- ggplot(cor_melt, aes(x = Var1, y = Var2, fill = value)) + geom_tile(colour = "black", linewidth = 0.3) + @@ -299,12 +301,16 @@ grid.arrange(p3_gsea, p3_gsea_inv, ncol = 2) ### Material Design -```{r, ggsci-material, fig.height=7.12} +```{r, ggsci-material, fig.height=3.8} set.seed(42) -k <- 9 +k <- 6 x <- diag(k) x[upper.tri(x)] <- runif(sum(1:(k - 1)), 0, 1) -x_melt <- melt(x) +x_melt <- data.frame( + Var1 = rep(seq_len(nrow(x)), times = ncol(x)), + Var2 = rep(seq_len(ncol(x)), each = nrow(x)), + value = as.vector(x) +) p4 <- ggplot(x_melt, aes(x = Var1, y = Var2, fill = value)) + geom_tile(colour = "black", linewidth = 0.3) + @@ -331,7 +337,7 @@ grid.arrange( p4 + scale_fill_material("orange"), p4 + scale_fill_material("deep-orange"), p4 + scale_fill_material("brown"), p4 + scale_fill_material("grey"), p4 + scale_fill_material("blue-grey"), - ncol = 6 + ncol = 8 ) ``` diff --git a/man/figures/README-ggsci-gsea-1.png b/man/figures/README-ggsci-gsea-1.png index a461641..775a161 100644 Binary files a/man/figures/README-ggsci-gsea-1.png and b/man/figures/README-ggsci-gsea-1.png differ diff --git a/man/figures/README-ggsci-material-1.png b/man/figures/README-ggsci-material-1.png index 6842716..139109b 100644 Binary files a/man/figures/README-ggsci-material-1.png and b/man/figures/README-ggsci-material-1.png differ diff --git a/man/scale_gsea.Rd b/man/scale_gsea.Rd index 6a2617a..382c083 100644 --- a/man/scale_gsea.Rd +++ b/man/scale_gsea.Rd @@ -29,11 +29,14 @@ See \code{\link[=pal_gsea]{pal_gsea()}} for details. } \examples{ library("ggplot2") -library("reshape2") -data("mtcars") +data("mtcars") cor <- cor(mtcars) -cor_melt <- melt(cor) +cor_melt <- data.frame( + Var1 = rep(seq_len(nrow(cor)), times = ncol(cor)), + Var2 = rep(seq_len(ncol(cor)), each = nrow(cor)), + value = as.vector(cor) +) ggplot( cor_melt, diff --git a/man/scale_material.Rd b/man/scale_material.Rd index daf1755..d919073 100644 --- a/man/scale_material.Rd +++ b/man/scale_material.Rd @@ -71,11 +71,14 @@ See \code{\link[=pal_material]{pal_material()}} for details. } \examples{ library("ggplot2") -library("reshape2") -data("mtcars") +data("mtcars") cor <- abs(cor(mtcars)) -cor_melt <- melt(cor) +cor_melt <- data.frame( + Var1 = rep(seq_len(nrow(cor)), times = ncol(cor)), + Var2 = rep(seq_len(ncol(cor)), each = nrow(cor)), + value = as.vector(cor) +) ggplot( cor_melt, diff --git a/vignettes/ggsci.Rmd b/vignettes/ggsci.Rmd index fa2f9dc..86bcef5 100644 --- a/vignettes/ggsci.Rmd +++ b/vignettes/ggsci.Rmd @@ -424,16 +424,15 @@ We will use a correlation matrix visualization (a special type of heatmap) to demonstrate the continuous color palettes in ggsci. ```{r} -library("reshape2") - data("mtcars") -cor <- cor(unname(cbind(mtcars, mtcars, mtcars, mtcars))) -cor_melt <- melt(cor) +cor <- cor(unname(mtcars)) +cor_melt <- data.frame( + Var1 = rep(seq_len(nrow(cor)), times = ncol(cor)), + Var2 = rep(seq_len(ncol(cor)), each = nrow(cor)), + value = as.vector(cor) +) -p3 <- ggplot( - cor_melt, - aes(x = Var1, y = Var2, fill = value) -) + +p3 <- ggplot(cor_melt, aes(x = Var1, y = Var2, fill = value)) + geom_tile(colour = "black", linewidth = 0.3) + theme_void() + theme( @@ -461,13 +460,15 @@ The Material Design color palettes are from the We generate a random matrix first: ```{r} -library("reshape2") - set.seed(42) -k <- 9 +k <- 6 x <- diag(k) x[upper.tri(x)] <- runif(sum(1:(k - 1)), 0, 1) -x_melt <- melt(x) +x_melt <- data.frame( + Var1 = rep(seq_len(nrow(x)), times = ncol(x)), + Var2 = rep(seq_len(ncol(x)), each = nrow(x)), + value = as.vector(x) +) p4 <- ggplot(x_melt, aes(x = Var1, y = Var2, fill = value)) + geom_tile(colour = "black", linewidth = 0.3) + @@ -486,7 +487,7 @@ p4 <- ggplot(x_melt, aes(x = Var1, y = Var2, fill = value)) + Plot the matrix with the 19 material design color palettes: -```{r, fig.height=7.12} +```{r, fig.height=3.8} grid.arrange( p4 + scale_fill_material("red"), p4 + scale_fill_material("pink"), p4 + scale_fill_material("purple"), p4 + scale_fill_material("deep-purple"), @@ -498,7 +499,7 @@ grid.arrange( p4 + scale_fill_material("orange"), p4 + scale_fill_material("deep-orange"), p4 + scale_fill_material("brown"), p4 + scale_fill_material("grey"), p4 + scale_fill_material("blue-grey"), - ncol = 6 + ncol = 8 ) ``` @@ -517,8 +518,7 @@ palette generator functions in the table above. For example: mypal <- pal_npg("nrc", alpha = 0.7)(9) mypal -library("scales") -show_col(mypal) +scales::show_col(mypal) ``` You will be able to use the generated hex color codes for such