Skip to content

Commit

Permalink
Merge pull request #46 from nanxstats/continuous-example
Browse files Browse the repository at this point in the history
Compact continuous example
  • Loading branch information
nanxstats committed Jun 10, 2024
2 parents 21db0d6 + 3842a79 commit 3bb5ac4
Show file tree
Hide file tree
Showing 10 changed files with 56 additions and 37 deletions.
1 change: 0 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ Suggests:
gridExtra,
knitr,
ragg,
reshape2,
rmarkdown
VignetteBuilder: knitr
Encoding: UTF-8
Expand Down
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
9 changes: 6 additions & 3 deletions R/continuous-gsea.R
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
9 changes: 6 additions & 3 deletions R/continuous-material.R
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
22 changes: 14 additions & 8 deletions README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -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) +
Expand All @@ -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) +
Expand All @@ -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
)
```

Expand Down
Binary file modified man/figures/README-ggsci-gsea-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified man/figures/README-ggsci-material-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 6 additions & 3 deletions man/scale_gsea.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 6 additions & 3 deletions man/scale_material.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 16 additions & 16 deletions vignettes/ggsci.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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) +
Expand All @@ -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"),
Expand All @@ -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
)
```

Expand All @@ -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
Expand Down

0 comments on commit 3bb5ac4

Please sign in to comment.