Skip to content

Commit 3bb5ac4

Browse files
authored
Merge pull request #46 from nanxstats/continuous-example
Compact continuous example
2 parents 21db0d6 + 3842a79 commit 3bb5ac4

10 files changed

+56
-37
lines changed

DESCRIPTION

-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ Suggests:
2727
gridExtra,
2828
knitr,
2929
ragg,
30-
reshape2,
3130
rmarkdown
3231
VignetteBuilder: knitr
3332
Encoding: UTF-8

NEWS.md

+2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
This change enhances package development transparency, reduces unnecessary
1212
indirection, and simplifies contributions by avoiding the construction
1313
of the palette data using the R script in `data-raw/` (#42).
14+
- For continuous palette examples, remove the reshape2 dependency and
15+
use more compact grid layout to reduce output image size (#45).
1416

1517
# ggsci 3.1.0
1618

R/continuous-gsea.R

+6-3
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,14 @@ pal_gsea <- function(palette = c("default"), n = 12, alpha = 1, reverse = FALSE)
8383
#'
8484
#' @examples
8585
#' library("ggplot2")
86-
#' library("reshape2")
87-
#' data("mtcars")
8886
#'
87+
#' data("mtcars")
8988
#' cor <- cor(mtcars)
90-
#' cor_melt <- melt(cor)
89+
#' cor_melt <- data.frame(
90+
#' Var1 = rep(seq_len(nrow(cor)), times = ncol(cor)),
91+
#' Var2 = rep(seq_len(ncol(cor)), each = nrow(cor)),
92+
#' value = as.vector(cor)
93+
#' )
9194
#'
9295
#' ggplot(
9396
#' cor_melt,

R/continuous-material.R

+6-3
Original file line numberDiff line numberDiff line change
@@ -113,11 +113,14 @@ pal_material <- function(
113113
#'
114114
#' @examples
115115
#' library("ggplot2")
116-
#' library("reshape2")
117-
#' data("mtcars")
118116
#'
117+
#' data("mtcars")
119118
#' cor <- abs(cor(mtcars))
120-
#' cor_melt <- melt(cor)
119+
#' cor_melt <- data.frame(
120+
#' Var1 = rep(seq_len(nrow(cor)), times = ncol(cor)),
121+
#' Var2 = rep(seq_len(ncol(cor)), each = nrow(cor)),
122+
#' value = as.vector(cor)
123+
#' )
121124
#'
122125
#' ggplot(
123126
#' cor_melt,

README.Rmd

+14-8
Original file line numberDiff line numberDiff line change
@@ -279,11 +279,13 @@ grid.arrange(p1_frontiers, p2_frontiers, ncol = 2)
279279
### GSEA
280280

281281
```{r}
282-
library("reshape2")
283-
284282
data("mtcars")
285-
cor <- cor(unname(cbind(mtcars, mtcars, mtcars, mtcars)))
286-
cor_melt <- melt(cor)
283+
cor <- cor(unname(mtcars))
284+
cor_melt <- data.frame(
285+
Var1 = rep(seq_len(nrow(cor)), times = ncol(cor)),
286+
Var2 = rep(seq_len(ncol(cor)), each = nrow(cor)),
287+
value = as.vector(cor)
288+
)
287289
288290
p3 <- ggplot(cor_melt, aes(x = Var1, y = Var2, fill = value)) +
289291
geom_tile(colour = "black", linewidth = 0.3) +
@@ -299,12 +301,16 @@ grid.arrange(p3_gsea, p3_gsea_inv, ncol = 2)
299301

300302
### Material Design
301303

302-
```{r, ggsci-material, fig.height=7.12}
304+
```{r, ggsci-material, fig.height=3.8}
303305
set.seed(42)
304-
k <- 9
306+
k <- 6
305307
x <- diag(k)
306308
x[upper.tri(x)] <- runif(sum(1:(k - 1)), 0, 1)
307-
x_melt <- melt(x)
309+
x_melt <- data.frame(
310+
Var1 = rep(seq_len(nrow(x)), times = ncol(x)),
311+
Var2 = rep(seq_len(ncol(x)), each = nrow(x)),
312+
value = as.vector(x)
313+
)
308314
309315
p4 <- ggplot(x_melt, aes(x = Var1, y = Var2, fill = value)) +
310316
geom_tile(colour = "black", linewidth = 0.3) +
@@ -331,7 +337,7 @@ grid.arrange(
331337
p4 + scale_fill_material("orange"), p4 + scale_fill_material("deep-orange"),
332338
p4 + scale_fill_material("brown"), p4 + scale_fill_material("grey"),
333339
p4 + scale_fill_material("blue-grey"),
334-
ncol = 6
340+
ncol = 8
335341
)
336342
```
337343

man/figures/README-ggsci-gsea-1.png

-55.1 KB
Loading
-84.1 KB
Loading

man/scale_gsea.Rd

+6-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/scale_material.Rd

+6-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vignettes/ggsci.Rmd

+16-16
Original file line numberDiff line numberDiff line change
@@ -424,16 +424,15 @@ We will use a correlation matrix visualization (a special type of heatmap)
424424
to demonstrate the continuous color palettes in ggsci.
425425

426426
```{r}
427-
library("reshape2")
428-
429427
data("mtcars")
430-
cor <- cor(unname(cbind(mtcars, mtcars, mtcars, mtcars)))
431-
cor_melt <- melt(cor)
428+
cor <- cor(unname(mtcars))
429+
cor_melt <- data.frame(
430+
Var1 = rep(seq_len(nrow(cor)), times = ncol(cor)),
431+
Var2 = rep(seq_len(ncol(cor)), each = nrow(cor)),
432+
value = as.vector(cor)
433+
)
432434
433-
p3 <- ggplot(
434-
cor_melt,
435-
aes(x = Var1, y = Var2, fill = value)
436-
) +
435+
p3 <- ggplot(cor_melt, aes(x = Var1, y = Var2, fill = value)) +
437436
geom_tile(colour = "black", linewidth = 0.3) +
438437
theme_void() +
439438
theme(
@@ -461,13 +460,15 @@ The Material Design color palettes are from the
461460
We generate a random matrix first:
462461

463462
```{r}
464-
library("reshape2")
465-
466463
set.seed(42)
467-
k <- 9
464+
k <- 6
468465
x <- diag(k)
469466
x[upper.tri(x)] <- runif(sum(1:(k - 1)), 0, 1)
470-
x_melt <- melt(x)
467+
x_melt <- data.frame(
468+
Var1 = rep(seq_len(nrow(x)), times = ncol(x)),
469+
Var2 = rep(seq_len(ncol(x)), each = nrow(x)),
470+
value = as.vector(x)
471+
)
471472
472473
p4 <- ggplot(x_melt, aes(x = Var1, y = Var2, fill = value)) +
473474
geom_tile(colour = "black", linewidth = 0.3) +
@@ -486,7 +487,7 @@ p4 <- ggplot(x_melt, aes(x = Var1, y = Var2, fill = value)) +
486487

487488
Plot the matrix with the 19 material design color palettes:
488489

489-
```{r, fig.height=7.12}
490+
```{r, fig.height=3.8}
490491
grid.arrange(
491492
p4 + scale_fill_material("red"), p4 + scale_fill_material("pink"),
492493
p4 + scale_fill_material("purple"), p4 + scale_fill_material("deep-purple"),
@@ -498,7 +499,7 @@ grid.arrange(
498499
p4 + scale_fill_material("orange"), p4 + scale_fill_material("deep-orange"),
499500
p4 + scale_fill_material("brown"), p4 + scale_fill_material("grey"),
500501
p4 + scale_fill_material("blue-grey"),
501-
ncol = 6
502+
ncol = 8
502503
)
503504
```
504505

@@ -517,8 +518,7 @@ palette generator functions in the table above. For example:
517518
mypal <- pal_npg("nrc", alpha = 0.7)(9)
518519
mypal
519520
520-
library("scales")
521-
show_col(mypal)
521+
scales::show_col(mypal)
522522
```
523523

524524
You will be able to use the generated hex color codes for such

0 commit comments

Comments
 (0)