diff --git a/DESCRIPTION b/DESCRIPTION index e86ad04..086c44b 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Package: ggsci Type: Package Title: Scientific Journal and Sci-Fi Themed Color Palettes for 'ggplot2' -Version: 3.2.0 +Version: 3.2.0.9000 Authors@R: c( person("Nan", "Xiao", email = "me@nanx.me", role = c("aut", "cre", "cph"), comment = c(ORCID = "0000-0002-0250-5673")), @@ -23,6 +23,7 @@ Depends: Imports: ggplot2 (>= 2.0.0), grDevices, + rlang, scales Suggests: gridExtra, @@ -31,5 +32,5 @@ Suggests: rmarkdown VignetteBuilder: knitr Encoding: UTF-8 -RoxygenNote: 7.3.2 +RoxygenNote: 7.3.3 Roxygen: list(markdown = TRUE) diff --git a/NAMESPACE b/NAMESPACE index e4624e5..a43b15c 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -1,5 +1,7 @@ # Generated by roxygen2: do not edit by hand +export(example_barplot) +export(example_scatterplot) export(pal_aaas) export(pal_bmj) export(pal_bs5) @@ -110,4 +112,5 @@ importFrom(ggplot2,scale_fill_gradientn) importFrom(grDevices,col2rgb) importFrom(grDevices,colorRamp) importFrom(grDevices,rgb) +importFrom(rlang,.data) importFrom(scales,manual_pal) diff --git a/NEWS.md b/NEWS.md index c74ddd7..32f675e 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,13 @@ +# ggsci 3.2.0.9000 + +## Improvements + +- Add `example_scatterplot()` and `example_barplot()` to simplify + discrete scale examples in documentation. This reduces boilerplate code + and makes it easier to maintain the examples. + Also improves graphical appearance of the examples by using a minimalist + theme with alternative data subsets. + # ggsci 3.2.0 ## New features diff --git a/R/discrete-aaas.R b/R/discrete-aaas.R index 98e0dc0..9d2bb15 100644 --- a/R/discrete-aaas.R +++ b/R/discrete-aaas.R @@ -53,25 +53,8 @@ pal_aaas <- function(palette = c("default"), alpha = 1) { #' @rdname scale_aaas #' #' @examples -#' library("ggplot2") -#' data("diamonds") -#' -#' ggplot( -#' subset(diamonds, carat >= 2.2), -#' aes(x = table, y = price, colour = cut) -#' ) + -#' geom_point(alpha = 0.7) + -#' geom_smooth(method = "loess", alpha = 0.1, size = 1, span = 1) + -#' theme_bw() + -#' scale_color_aaas() -#' -#' ggplot( -#' subset(diamonds, carat > 2.2 & depth > 55 & depth < 70), -#' aes(x = depth, fill = cut) -#' ) + -#' geom_histogram(colour = "black", binwidth = 1, position = "dodge") + -#' theme_bw() + -#' scale_fill_aaas() +#' example_scatterplot() + scale_color_aaas() +#' example_barplot() + scale_fill_aaas() scale_color_aaas <- function(palette = c("default"), alpha = 1, ...) { palette <- match.arg(palette) if (is_ggplot2_350()) { diff --git a/R/discrete-bmj.R b/R/discrete-bmj.R index 0673378..03e3a65 100644 --- a/R/discrete-bmj.R +++ b/R/discrete-bmj.R @@ -57,25 +57,8 @@ pal_bmj <- function(palette = c("default"), alpha = 1) { #' #' #' @examples -#' library("ggplot2") -#' data("diamonds") -#' -#' ggplot( -#' subset(diamonds, carat >= 2.2), -#' aes(x = table, y = price, colour = cut) -#' ) + -#' geom_point(alpha = 0.7) + -#' geom_smooth(method = "loess", alpha = 0.1, size = 1, span = 1) + -#' theme_bw() + -#' scale_color_bmj() -#' -#' ggplot( -#' subset(diamonds, carat > 2.2 & depth > 55 & depth < 70), -#' aes(x = depth, fill = cut) -#' ) + -#' geom_histogram(colour = "black", binwidth = 1, position = "dodge") + -#' theme_bw() + -#' scale_fill_bmj() +#' example_scatterplot() + scale_color_bmj() +#' example_barplot() + scale_fill_bmj() scale_color_bmj <- function(palette = c("default"), alpha = 1, ...) { palette <- match.arg(palette) if (is_ggplot2_350()) { diff --git a/R/discrete-cosmic.R b/R/discrete-cosmic.R index d8c048e..d2db128 100644 --- a/R/discrete-cosmic.R +++ b/R/discrete-cosmic.R @@ -65,25 +65,8 @@ pal_cosmic <- function( #' @rdname scale_cosmic #' #' @examples -#' library("ggplot2") -#' data("diamonds") -#' -#' ggplot( -#' subset(diamonds, carat >= 2.2), -#' aes(x = table, y = price, colour = cut) -#' ) + -#' geom_point(alpha = 0.7) + -#' geom_smooth(method = "loess", alpha = 0.1, size = 1, span = 1) + -#' theme_bw() + -#' scale_color_cosmic() -#' -#' ggplot( -#' subset(diamonds, carat > 2.2 & depth > 55 & depth < 70), -#' aes(x = depth, fill = cut) -#' ) + -#' geom_histogram(colour = "black", binwidth = 1, position = "dodge") + -#' theme_bw() + -#' scale_fill_cosmic() +#' example_scatterplot() + scale_color_cosmic() +#' example_barplot() + scale_fill_cosmic() scale_color_cosmic <- function( palette = c("hallmarks_light", "hallmarks_dark", "signature_substitutions"), alpha = 1, ...) { diff --git a/R/discrete-d3.R b/R/discrete-d3.R index e5bee25..9510f7d 100644 --- a/R/discrete-d3.R +++ b/R/discrete-d3.R @@ -61,23 +61,8 @@ pal_d3 <- function(palette = c("category10", "category20", "category20b", "categ #' @rdname scale_d3 #' #' @examples -#' library("ggplot2") -#' data("diamonds") -#' -#' p1 <- ggplot( -#' subset(diamonds, carat >= 2.2), -#' aes(x = table, y = price, colour = cut) -#' ) + -#' geom_point(alpha = 0.7) + -#' geom_smooth(method = "loess", alpha = 0.1, size = 1, span = 1) + -#' theme_bw() -#' -#' p2 <- ggplot( -#' subset(diamonds, carat > 2.2 & depth > 55 & depth < 70), -#' aes(x = depth, fill = cut) -#' ) + -#' geom_histogram(colour = "black", binwidth = 1, position = "dodge") + -#' theme_bw() +#' p1 <- example_scatterplot() +#' p2 <- example_barplot() #' #' p1 + scale_color_d3() #' p2 + scale_fill_d3() diff --git a/R/discrete-flatui.R b/R/discrete-flatui.R index 9c5c2d5..1e12ea0 100644 --- a/R/discrete-flatui.R +++ b/R/discrete-flatui.R @@ -54,23 +54,8 @@ pal_flatui <- function(palette = c("default", "flattastic", "aussie"), alpha = 1 #' @rdname scale_flatui #' #' @examples -#' library("ggplot2") -#' data("diamonds") -#' -#' p1 <- ggplot( -#' subset(diamonds, carat >= 2.2), -#' aes(x = table, y = price, colour = cut) -#' ) + -#' geom_point(alpha = 0.7) + -#' geom_smooth(method = "loess", alpha = 0.1, size = 1, span = 1) + -#' theme_bw() -#' -#' p2 <- ggplot( -#' subset(diamonds, carat > 2.2 & depth > 55 & depth < 70), -#' aes(x = depth, fill = cut) -#' ) + -#' geom_histogram(colour = "black", binwidth = 1, position = "dodge") + -#' theme_bw() +#' p1 <- example_scatterplot() +#' p2 <- example_barplot() #' #' p1 + scale_color_flatui() #' p2 + scale_fill_flatui() diff --git a/R/discrete-frontiers.R b/R/discrete-frontiers.R index 7128840..5c0e91c 100644 --- a/R/discrete-frontiers.R +++ b/R/discrete-frontiers.R @@ -51,30 +51,18 @@ pal_frontiers <- function(palette = c("default"), alpha = 1) { #' @rdname scale_frontiers #' #' @examples -#' library("ggplot2") -#' data("diamonds") -#' -#' ggplot( -#' subset(diamonds, carat >= 2.2), -#' aes(x = table, y = price, colour = cut) -#' ) + -#' geom_point(alpha = 0.7) + -#' geom_smooth(method = "loess", alpha = 0.1, size = 1, span = 1) + -#' theme_dark() + -#' theme( -#' panel.background = element_rect(fill = "#2D2D2D"), -#' legend.key = element_rect(fill = "#2D2D2D") +#' example_scatterplot() + +#' ggplot2::theme_dark() + +#' ggplot2::theme( +#' panel.background = ggplot2::element_rect(fill = "#2D2D2D"), +#' legend.key = ggplot2::element_rect(fill = "#2D2D2D") #' ) + #' scale_color_frontiers() #' -#' ggplot( -#' subset(diamonds, carat > 2.2 & depth > 55 & depth < 70), -#' aes(x = depth, fill = cut) -#' ) + -#' geom_histogram(colour = "black", binwidth = 1, position = "dodge") + -#' theme_dark() + -#' theme( -#' panel.background = element_rect(fill = "#2D2D2D") +#' example_barplot() + +#' ggplot2::theme_dark() + +#' ggplot2::theme( +#' panel.background = ggplot2::element_rect(fill = "#2D2D2D") #' ) + #' scale_fill_frontiers() scale_color_frontiers <- function(palette = c("default"), alpha = 1, ...) { diff --git a/R/discrete-futurama.R b/R/discrete-futurama.R index 6f6b1c9..39ecdd2 100644 --- a/R/discrete-futurama.R +++ b/R/discrete-futurama.R @@ -51,25 +51,8 @@ pal_futurama <- function(palette = c("planetexpress"), alpha = 1) { #' @rdname scale_futurama #' #' @examples -#' library("ggplot2") -#' data("diamonds") -#' -#' ggplot( -#' subset(diamonds, carat >= 2.2), -#' aes(x = table, y = price, colour = cut) -#' ) + -#' geom_point(alpha = 0.7) + -#' geom_smooth(method = "loess", alpha = 0.1, size = 1, span = 1) + -#' theme_bw() + -#' scale_color_futurama() -#' -#' ggplot( -#' subset(diamonds, carat > 2.2 & depth > 55 & depth < 70), -#' aes(x = depth, fill = cut) -#' ) + -#' geom_histogram(colour = "black", binwidth = 1, position = "dodge") + -#' theme_bw() + -#' scale_fill_futurama() +#' example_scatterplot() + scale_color_futurama() +#' example_barplot() + scale_fill_futurama() scale_color_futurama <- function(palette = c("planetexpress"), alpha = 1, ...) { palette <- match.arg(palette) if (is_ggplot2_350()) { diff --git a/R/discrete-igv.R b/R/discrete-igv.R index 8923bb3..3b90917 100644 --- a/R/discrete-igv.R +++ b/R/discrete-igv.R @@ -58,31 +58,16 @@ pal_igv <- function(palette = c("default", "alternating"), alpha = 1) { #' @rdname scale_igv #' #' @examples -#' library("ggplot2") -#' data("diamonds") -#' -#' p1 <- ggplot( -#' subset(diamonds, carat >= 2.2), -#' aes(x = table, y = price, colour = cut) -#' ) + -#' geom_point(alpha = 0.7) + -#' geom_smooth(method = "loess", alpha = 0.1, size = 1, span = 1) + -#' theme_bw() -#' -#' p2 <- ggplot( -#' subset(diamonds, carat > 2.2 & depth > 55 & depth < 70), -#' aes(x = depth, fill = cut) -#' ) + -#' geom_histogram(colour = "black", binwidth = 1, position = "dodge") + -#' theme_bw() +#' p1 <- example_scatterplot() +#' p2 <- example_barplot() #' #' p1 + scale_color_igv() #' p2 + scale_fill_igv() #' -#' p1 + scale_colour_manual( +#' p1 + ggplot2::scale_colour_manual( #' values = rep(pal_igv("alternating")(2), times = 3) #' ) -#' p2 + scale_fill_manual( +#' p2 + ggplot2::scale_fill_manual( #' values = rep(pal_igv("alternating")(2), times = 3) #' ) scale_color_igv <- function(palette = c("default", "alternating"), alpha = 1, ...) { diff --git a/R/discrete-jama.R b/R/discrete-jama.R index b194515..03c3ac6 100644 --- a/R/discrete-jama.R +++ b/R/discrete-jama.R @@ -52,25 +52,8 @@ pal_jama <- function(palette = c("default"), alpha = 1) { #' @rdname scale_jama #' #' @examples -#' library("ggplot2") -#' data("diamonds") -#' -#' ggplot( -#' subset(diamonds, carat >= 2.2), -#' aes(x = table, y = price, colour = cut) -#' ) + -#' geom_point(alpha = 0.7) + -#' geom_smooth(method = "loess", alpha = 0.1, size = 1, span = 1) + -#' theme_bw() + -#' scale_color_jama() -#' -#' ggplot( -#' subset(diamonds, carat > 2.2 & depth > 55 & depth < 70), -#' aes(x = depth, fill = cut) -#' ) + -#' geom_histogram(colour = "black", binwidth = 1, position = "dodge") + -#' theme_bw() + -#' scale_fill_jama() +#' example_scatterplot() + scale_color_jama() +#' example_barplot() + scale_fill_jama() scale_color_jama <- function(palette = c("default"), alpha = 1, ...) { palette <- match.arg(palette) if (is_ggplot2_350()) { diff --git a/R/discrete-jco.R b/R/discrete-jco.R index e45474b..df9ddd3 100644 --- a/R/discrete-jco.R +++ b/R/discrete-jco.R @@ -51,25 +51,8 @@ pal_jco <- function(palette = c("default"), alpha = 1) { #' @rdname scale_jco #' #' @examples -#' library("ggplot2") -#' data("diamonds") -#' -#' ggplot( -#' subset(diamonds, carat >= 2.2), -#' aes(x = table, y = price, colour = cut) -#' ) + -#' geom_point(alpha = 0.7) + -#' geom_smooth(method = "loess", alpha = 0.1, size = 1, span = 1) + -#' theme_bw() + -#' scale_color_jco() -#' -#' ggplot( -#' subset(diamonds, carat > 2.2 & depth > 55 & depth < 70), -#' aes(x = depth, fill = cut) -#' ) + -#' geom_histogram(colour = "black", binwidth = 1, position = "dodge") + -#' theme_bw() + -#' scale_fill_jco() +#' example_scatterplot() + scale_color_jco() +#' example_barplot() + scale_fill_jco() scale_color_jco <- function(palette = c("default"), alpha = 1, ...) { palette <- match.arg(palette) if (is_ggplot2_350()) { diff --git a/R/discrete-lancet.R b/R/discrete-lancet.R index b0e62ad..74e979d 100644 --- a/R/discrete-lancet.R +++ b/R/discrete-lancet.R @@ -52,25 +52,8 @@ pal_lancet <- function(palette = c("lanonc"), alpha = 1) { #' @rdname scale_lancet #' #' @examples -#' library("ggplot2") -#' data("diamonds") -#' -#' ggplot( -#' subset(diamonds, carat >= 2.2), -#' aes(x = table, y = price, colour = cut) -#' ) + -#' geom_point(alpha = 0.7) + -#' geom_smooth(method = "loess", alpha = 0.1, size = 1, span = 1) + -#' theme_bw() + -#' scale_color_lancet() -#' -#' ggplot( -#' subset(diamonds, carat > 2.2 & depth > 55 & depth < 70), -#' aes(x = depth, fill = cut) -#' ) + -#' geom_histogram(colour = "black", binwidth = 1, position = "dodge") + -#' theme_bw() + -#' scale_fill_lancet() +#' example_scatterplot() + scale_color_lancet() +#' example_barplot() + scale_fill_lancet() scale_color_lancet <- function(palette = c("lanonc"), alpha = 1, ...) { palette <- match.arg(palette) if (is_ggplot2_350()) { diff --git a/R/discrete-locuszoom.R b/R/discrete-locuszoom.R index 54485e8..d3b43c9 100644 --- a/R/discrete-locuszoom.R +++ b/R/discrete-locuszoom.R @@ -56,25 +56,8 @@ pal_locuszoom <- function(palette = c("default"), alpha = 1) { #' @rdname scale_locuszoom #' #' @examples -#' library("ggplot2") -#' data("diamonds") -#' -#' ggplot( -#' subset(diamonds, carat >= 2.2), -#' aes(x = table, y = price, colour = cut) -#' ) + -#' geom_point(alpha = 0.7) + -#' geom_smooth(method = "loess", alpha = 0.1, size = 1, span = 1) + -#' theme_bw() + -#' scale_color_locuszoom() -#' -#' ggplot( -#' subset(diamonds, carat > 2.2 & depth > 55 & depth < 70), -#' aes(x = depth, fill = cut) -#' ) + -#' geom_histogram(colour = "black", binwidth = 1, position = "dodge") + -#' theme_bw() + -#' scale_fill_locuszoom() +#' example_scatterplot() + scale_color_locuszoom() +#' example_barplot() + scale_fill_locuszoom() scale_color_locuszoom <- function(palette = c("default"), alpha = 1, ...) { palette <- match.arg(palette) if (is_ggplot2_350()) { diff --git a/R/discrete-nejm.R b/R/discrete-nejm.R index 56ac48b..5b02513 100644 --- a/R/discrete-nejm.R +++ b/R/discrete-nejm.R @@ -52,25 +52,8 @@ pal_nejm <- function(palette = c("default"), alpha = 1) { #' @rdname scale_nejm #' #' @examples -#' library("ggplot2") -#' data("diamonds") -#' -#' ggplot( -#' subset(diamonds, carat >= 2.2), -#' aes(x = table, y = price, colour = cut) -#' ) + -#' geom_point(alpha = 0.7) + -#' geom_smooth(method = "loess", alpha = 0.1, size = 1, span = 1) + -#' theme_bw() + -#' scale_color_nejm() -#' -#' ggplot( -#' subset(diamonds, carat > 2.2 & depth > 55 & depth < 70), -#' aes(x = depth, fill = cut) -#' ) + -#' geom_histogram(colour = "black", binwidth = 1, position = "dodge") + -#' theme_bw() + -#' scale_fill_nejm() +#' example_scatterplot() + scale_color_nejm() +#' example_barplot() + scale_fill_nejm() scale_color_nejm <- function(palette = c("default"), alpha = 1, ...) { palette <- match.arg(palette) if (is_ggplot2_350()) { diff --git a/R/discrete-npg.R b/R/discrete-npg.R index dd2ecd7..38d9c84 100644 --- a/R/discrete-npg.R +++ b/R/discrete-npg.R @@ -52,25 +52,8 @@ pal_npg <- function(palette = c("nrc"), alpha = 1) { #' @rdname scale_npg #' #' @examples -#' library("ggplot2") -#' data("diamonds") -#' -#' ggplot( -#' subset(diamonds, carat >= 2.2), -#' aes(x = table, y = price, colour = cut) -#' ) + -#' geom_point(alpha = 0.7) + -#' geom_smooth(method = "loess", alpha = 0.1, size = 1, span = 1) + -#' theme_bw() + -#' scale_color_npg() -#' -#' ggplot( -#' subset(diamonds, carat > 2.2 & depth > 55 & depth < 70), -#' aes(x = depth, fill = cut) -#' ) + -#' geom_histogram(colour = "black", binwidth = 1, position = "dodge") + -#' theme_bw() + -#' scale_fill_npg() +#' example_scatterplot() + scale_color_npg() +#' example_barplot() + scale_fill_npg() scale_color_npg <- function(palette = c("nrc"), alpha = 1, ...) { palette <- match.arg(palette) if (is_ggplot2_350()) { diff --git a/R/discrete-observable.R b/R/discrete-observable.R index c2d74a0..99f29d1 100644 --- a/R/discrete-observable.R +++ b/R/discrete-observable.R @@ -59,25 +59,8 @@ pal_observable <- function(palette = c("observable10"), alpha = 1) { #' @rdname scale_observable #' #' @examples -#' library("ggplot2") -#' data("diamonds") -#' -#' ggplot( -#' subset(diamonds, carat >= 2.2), -#' aes(x = table, y = price, colour = cut) -#' ) + -#' geom_point(alpha = 0.7) + -#' geom_smooth(method = "loess", alpha = 0.1, size = 1, span = 1) + -#' theme_bw() + -#' scale_color_observable() -#' -#' ggplot( -#' subset(diamonds, carat > 2.2 & depth > 55 & depth < 70), -#' aes(x = depth, fill = cut) -#' ) + -#' geom_histogram(colour = "black", binwidth = 1, position = "dodge") + -#' theme_bw() + -#' scale_fill_observable() +#' example_scatterplot() + scale_color_observable() +#' example_barplot() + scale_fill_observable() scale_color_observable <- function(palette = c("observable10"), alpha = 1, ...) { palette <- match.arg(palette) if (is_ggplot2_350()) { diff --git a/R/discrete-rickandmorty.R b/R/discrete-rickandmorty.R index bf44858..fdfa32a 100644 --- a/R/discrete-rickandmorty.R +++ b/R/discrete-rickandmorty.R @@ -51,25 +51,8 @@ pal_rickandmorty <- function(palette = c("schwifty"), alpha = 1) { #' @rdname scale_rickandmorty #' #' @examples -#' library("ggplot2") -#' data("diamonds") -#' -#' ggplot( -#' subset(diamonds, carat >= 2.2), -#' aes(x = table, y = price, colour = cut) -#' ) + -#' geom_point(alpha = 0.7) + -#' geom_smooth(method = "loess", alpha = 0.1, size = 1, span = 1) + -#' theme_bw() + -#' scale_color_rickandmorty() -#' -#' ggplot( -#' subset(diamonds, carat > 2.2 & depth > 55 & depth < 70), -#' aes(x = depth, fill = cut) -#' ) + -#' geom_histogram(colour = "black", binwidth = 1, position = "dodge") + -#' theme_bw() + -#' scale_fill_rickandmorty() +#' example_scatterplot() + scale_color_rickandmorty() +#' example_barplot() + scale_fill_rickandmorty() scale_color_rickandmorty <- function(palette = c("schwifty"), alpha = 1, ...) { palette <- match.arg(palette) if (is_ggplot2_350()) { diff --git a/R/discrete-simpsons.R b/R/discrete-simpsons.R index 516ed98..2243e7c 100644 --- a/R/discrete-simpsons.R +++ b/R/discrete-simpsons.R @@ -51,25 +51,8 @@ pal_simpsons <- function(palette = c("springfield"), alpha = 1) { #' @rdname scale_simpsons #' #' @examples -#' library("ggplot2") -#' data("diamonds") -#' -#' ggplot( -#' subset(diamonds, carat >= 2.2), -#' aes(x = table, y = price, colour = cut) -#' ) + -#' geom_point(alpha = 0.7) + -#' geom_smooth(method = "loess", alpha = 0.1, size = 1, span = 1) + -#' theme_bw() + -#' scale_color_simpsons() -#' -#' ggplot( -#' subset(diamonds, carat > 2.2 & depth > 55 & depth < 70), -#' aes(x = depth, fill = cut) -#' ) + -#' geom_histogram(colour = "black", binwidth = 1, position = "dodge") + -#' theme_bw() + -#' scale_fill_simpsons() +#' example_scatterplot() + scale_color_simpsons() +#' example_barplot() + scale_fill_simpsons() scale_color_simpsons <- function(palette = c("springfield"), alpha = 1, ...) { palette <- match.arg(palette) if (is_ggplot2_350()) { diff --git a/R/discrete-startrek.R b/R/discrete-startrek.R index fc6d183..4c3461f 100644 --- a/R/discrete-startrek.R +++ b/R/discrete-startrek.R @@ -51,25 +51,8 @@ pal_startrek <- function(palette = c("uniform"), alpha = 1) { #' @rdname scale_startrek #' #' @examples -#' library("ggplot2") -#' data("diamonds") -#' -#' ggplot( -#' subset(diamonds, carat >= 2.2), -#' aes(x = table, y = price, colour = cut) -#' ) + -#' geom_point(alpha = 0.7) + -#' geom_smooth(method = "loess", alpha = 0.1, size = 1, span = 1) + -#' theme_bw() + -#' scale_color_startrek() -#' -#' ggplot( -#' subset(diamonds, carat > 2.2 & depth > 55 & depth < 70), -#' aes(x = depth, fill = cut) -#' ) + -#' geom_histogram(colour = "black", binwidth = 1, position = "dodge") + -#' theme_bw() + -#' scale_fill_startrek() +#' example_scatterplot() + scale_color_startrek() +#' example_barplot() + scale_fill_startrek() scale_color_startrek <- function(palette = c("uniform"), alpha = 1, ...) { palette <- match.arg(palette) if (is_ggplot2_350()) { diff --git a/R/discrete-tron.R b/R/discrete-tron.R index 746084e..4bfdc19 100644 --- a/R/discrete-tron.R +++ b/R/discrete-tron.R @@ -51,30 +51,18 @@ pal_tron <- function(palette = c("legacy"), alpha = 1) { #' @rdname scale_tron #' #' @examples -#' library("ggplot2") -#' data("diamonds") -#' -#' ggplot( -#' subset(diamonds, carat >= 2.2), -#' aes(x = table, y = price, colour = cut) -#' ) + -#' geom_point(alpha = 0.7) + -#' geom_smooth(method = "loess", alpha = 0.1, size = 1, span = 1) + -#' theme_dark() + -#' theme( -#' panel.background = element_rect(fill = "#2D2D2D"), -#' legend.key = element_rect(fill = "#2D2D2D") +#' example_scatterplot() + +#' ggplot2::theme_dark() + +#' ggplot2::theme( +#' panel.background = ggplot2::element_rect(fill = "#2D2D2D"), +#' legend.key = ggplot2::element_rect(fill = "#2D2D2D") #' ) + #' scale_color_tron() #' -#' ggplot( -#' subset(diamonds, carat > 2.2 & depth > 55 & depth < 70), -#' aes(x = depth, fill = cut) -#' ) + -#' geom_histogram(colour = "black", binwidth = 1, position = "dodge") + -#' theme_dark() + -#' theme( -#' panel.background = element_rect(fill = "#2D2D2D") +#' example_barplot() + +#' ggplot2::theme_dark() + +#' ggplot2::theme( +#' panel.background = ggplot2::element_rect(fill = "#2D2D2D") #' ) + #' scale_fill_tron() scale_color_tron <- function(palette = c("legacy"), alpha = 1, ...) { diff --git a/R/discrete-uchicago.R b/R/discrete-uchicago.R index 2e998c4..5e9f3f3 100644 --- a/R/discrete-uchicago.R +++ b/R/discrete-uchicago.R @@ -60,23 +60,8 @@ pal_uchicago <- function(palette = c("default", "light", "dark"), alpha = 1) { #' @rdname scale_uchicago #' #' @examples -#' library("ggplot2") -#' data("diamonds") -#' -#' p1 <- ggplot( -#' subset(diamonds, carat >= 2.2), -#' aes(x = table, y = price, colour = cut) -#' ) + -#' geom_point(alpha = 0.7) + -#' geom_smooth(method = "loess", alpha = 0.1, size = 1, span = 1) + -#' theme_bw() -#' -#' p2 <- ggplot( -#' subset(diamonds, carat > 2.2 & depth > 55 & depth < 70), -#' aes(x = depth, fill = cut) -#' ) + -#' geom_histogram(colour = "black", binwidth = 1, position = "dodge") + -#' theme_bw() +#' p1 <- example_scatterplot() +#' p2 <- example_barplot() #' #' p1 + scale_color_uchicago() #' p2 + scale_fill_uchicago() diff --git a/R/discrete-ucscgb.R b/R/discrete-ucscgb.R index 9f4fae2..c3dc284 100644 --- a/R/discrete-ucscgb.R +++ b/R/discrete-ucscgb.R @@ -51,25 +51,8 @@ pal_ucscgb <- function(palette = c("default"), alpha = 1) { #' @rdname scale_ucscgb #' #' @examples -#' library("ggplot2") -#' data("diamonds") -#' -#' ggplot( -#' subset(diamonds, carat >= 2.2), -#' aes(x = table, y = price, colour = cut) -#' ) + -#' geom_point(alpha = 0.7) + -#' geom_smooth(method = "loess", alpha = 0.1, size = 1, span = 1) + -#' theme_bw() + -#' scale_color_ucscgb() -#' -#' ggplot( -#' subset(diamonds, carat > 2.2 & depth > 55 & depth < 70), -#' aes(x = depth, fill = cut) -#' ) + -#' geom_histogram(colour = "black", binwidth = 1, position = "dodge") + -#' theme_bw() + -#' scale_fill_ucscgb() +#' example_scatterplot() + scale_color_ucscgb() +#' example_barplot() + scale_fill_ucscgb() scale_color_ucscgb <- function(palette = c("default"), alpha = 1, ...) { palette <- match.arg(palette) if (is_ggplot2_350()) { diff --git a/R/examples.R b/R/examples.R new file mode 100644 index 0000000..0143f7f --- /dev/null +++ b/R/examples.R @@ -0,0 +1,54 @@ +#' Example plots for discrete color palettes +#' +#' Utility functions that return simple ggplot2 examples to +#' demonstrate discrete color/fill scales. +#' +#' @details +#' - `example_scatterplot()` creates a scatter plot of large diamonds +#' (`carat >= 2.2`), mapping `table` to the x‑axis, `price` to the y‑axis, +#' and `cut` to color. +#' - `example_barplot()` creates a side‑by‑side bar chart of diamond counts +#' by `color`, grouped by `cut` via fill. +#' +#' @return A `ggplot` object. +#' +#' @rdname example_plots +#' +#' @importFrom rlang .data +#' +#' @export example_scatterplot +#' +#' @examples +#' example_scatterplot() +#' example_barplot() +example_scatterplot <- function() { + ggplot2::ggplot( + ggplot2::diamonds[ggplot2::diamonds$carat >= 2.2, ], + ggplot2::aes(x = .data$table, y = .data$price, colour = .data$cut) + ) + + ggplot2::geom_point(alpha = 0.7) + + ggplot2::geom_smooth(method = "loess", alpha = 0.05, linewidth = 1, span = 1) + + ggplot2::theme_minimal() + + ggplot2::theme( + axis.title.x = ggplot2::element_blank(), + axis.title.y = ggplot2::element_blank(), + panel.grid.minor = ggplot2::element_blank() + ) +} + +#' @rdname example_plots +#' @export example_barplot +example_barplot <- function() { + ggplot2::ggplot( + ggplot2::diamonds, + ggplot2::aes(x = .data$color, fill = .data$cut) + ) + + ggplot2::geom_bar(position = ggplot2::position_dodge()) + + ggplot2::theme_minimal() + + ggplot2::theme( + axis.title.x = ggplot2::element_blank(), + axis.title.y = ggplot2::element_blank(), + panel.grid.major.x = ggplot2::element_blank(), + panel.grid.minor.y = ggplot2::element_blank() + ) +} diff --git a/README.Rmd b/README.Rmd index 81541df..bc830ef 100644 --- a/README.Rmd +++ b/README.Rmd @@ -55,35 +55,15 @@ remotes::install_github("nanxstats/ggsci") ## Gallery -```{r} +```{r, message=FALSE, warning=FALSE} library("ggsci") library("ggplot2") library("gridExtra") +``` -data("diamonds") - -p1 <- ggplot( - subset(diamonds, carat >= 2.2), - aes(x = table, y = price, colour = cut) -) + - geom_point(alpha = 0.7) + - geom_smooth(method = "loess", alpha = 0.05, linewidth = 1, span = 1) + - theme_bw() + - theme( - axis.title.x = element_blank(), - axis.title.y = element_blank() - ) - -p2 <- ggplot( - subset(diamonds, carat > 2.2 & depth > 55 & depth < 70), - aes(x = depth, fill = cut) -) + - geom_histogram(colour = "black", binwidth = 1, position = "dodge") + - theme_bw() + - theme( - axis.title.x = element_blank(), - axis.title.y = element_blank() - ) +```{r} +p1 <- example_scatterplot() +p2 <- example_barplot() ``` ### NPG diff --git a/_pkgdown.yml b/_pkgdown.yml index b12be3f..b024d4f 100644 --- a/_pkgdown.yml +++ b/_pkgdown.yml @@ -160,3 +160,7 @@ reference: - scale_color_tw3 - scale_colour_tw3 - scale_fill_tw3 + - title: "Example plots" + contents: + - example_scatterplot + - example_barplot diff --git a/man/example_plots.Rd b/man/example_plots.Rd new file mode 100644 index 0000000..12c2c38 --- /dev/null +++ b/man/example_plots.Rd @@ -0,0 +1,31 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/examples.R +\name{example_scatterplot} +\alias{example_scatterplot} +\alias{example_barplot} +\title{Example plots for discrete color palettes} +\usage{ +example_scatterplot() + +example_barplot() +} +\value{ +A \code{ggplot} object. +} +\description{ +Utility functions that return simple ggplot2 examples to +demonstrate discrete color/fill scales. +} +\details{ +\itemize{ +\item \code{example_scatterplot()} creates a scatter plot of large diamonds +(\code{carat >= 2.2}), mapping \code{table} to the x‑axis, \code{price} to the y‑axis, +and \code{cut} to color. +\item \code{example_barplot()} creates a side‑by‑side bar chart of diamond counts +by \code{color}, grouped by \code{cut} via fill. +} +} +\examples{ +example_scatterplot() +example_barplot() +} diff --git a/man/figures/README-ggsci-aaas-1.png b/man/figures/README-ggsci-aaas-1.png index 1a6dc56..0a6f450 100644 Binary files a/man/figures/README-ggsci-aaas-1.png and b/man/figures/README-ggsci-aaas-1.png differ diff --git a/man/figures/README-ggsci-bmj-1.png b/man/figures/README-ggsci-bmj-1.png index 5f22fde..69f966b 100644 Binary files a/man/figures/README-ggsci-bmj-1.png and b/man/figures/README-ggsci-bmj-1.png differ diff --git a/man/figures/README-ggsci-bs5-1.png b/man/figures/README-ggsci-bs5-1.png index 96e5a17..1726198 100644 Binary files a/man/figures/README-ggsci-bs5-1.png and b/man/figures/README-ggsci-bs5-1.png differ diff --git a/man/figures/README-ggsci-cosmic-1.png b/man/figures/README-ggsci-cosmic-1.png index 2ec1083..0dfd6eb 100644 Binary files a/man/figures/README-ggsci-cosmic-1.png and b/man/figures/README-ggsci-cosmic-1.png differ diff --git a/man/figures/README-ggsci-cosmic-2.png b/man/figures/README-ggsci-cosmic-2.png index ffa1c51..3728510 100644 Binary files a/man/figures/README-ggsci-cosmic-2.png and b/man/figures/README-ggsci-cosmic-2.png differ diff --git a/man/figures/README-ggsci-cosmic-3.png b/man/figures/README-ggsci-cosmic-3.png index 9994372..abebb63 100644 Binary files a/man/figures/README-ggsci-cosmic-3.png and b/man/figures/README-ggsci-cosmic-3.png differ diff --git a/man/figures/README-ggsci-d3-1.png b/man/figures/README-ggsci-d3-1.png index a2b6c35..fa71a3d 100644 Binary files a/man/figures/README-ggsci-d3-1.png and b/man/figures/README-ggsci-d3-1.png differ diff --git a/man/figures/README-ggsci-flatui-1.png b/man/figures/README-ggsci-flatui-1.png index 91e9fe7..c5016a7 100644 Binary files a/man/figures/README-ggsci-flatui-1.png and b/man/figures/README-ggsci-flatui-1.png differ diff --git a/man/figures/README-ggsci-frontiers-1.png b/man/figures/README-ggsci-frontiers-1.png index 59b9ff5..c10767c 100644 Binary files a/man/figures/README-ggsci-frontiers-1.png and b/man/figures/README-ggsci-frontiers-1.png differ diff --git a/man/figures/README-ggsci-futurama-1.png b/man/figures/README-ggsci-futurama-1.png index bc4bafe..cd8a7dd 100644 Binary files a/man/figures/README-ggsci-futurama-1.png and b/man/figures/README-ggsci-futurama-1.png differ diff --git a/man/figures/README-ggsci-igv-1.png b/man/figures/README-ggsci-igv-1.png index a229a86..04e10fe 100644 Binary files a/man/figures/README-ggsci-igv-1.png and b/man/figures/README-ggsci-igv-1.png differ diff --git a/man/figures/README-ggsci-jama-1.png b/man/figures/README-ggsci-jama-1.png index d12f6ba..385eb8e 100644 Binary files a/man/figures/README-ggsci-jama-1.png and b/man/figures/README-ggsci-jama-1.png differ diff --git a/man/figures/README-ggsci-jco-1.png b/man/figures/README-ggsci-jco-1.png index d426b80..f262785 100644 Binary files a/man/figures/README-ggsci-jco-1.png and b/man/figures/README-ggsci-jco-1.png differ diff --git a/man/figures/README-ggsci-lancet-1.png b/man/figures/README-ggsci-lancet-1.png index ac23066..18f8200 100644 Binary files a/man/figures/README-ggsci-lancet-1.png and b/man/figures/README-ggsci-lancet-1.png differ diff --git a/man/figures/README-ggsci-locuszoom-1.png b/man/figures/README-ggsci-locuszoom-1.png index 68b8772..26c7788 100644 Binary files a/man/figures/README-ggsci-locuszoom-1.png and b/man/figures/README-ggsci-locuszoom-1.png differ diff --git a/man/figures/README-ggsci-material-1.png b/man/figures/README-ggsci-material-1.png index 139109b..276325a 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/figures/README-ggsci-nejm-1.png b/man/figures/README-ggsci-nejm-1.png index 9411a61..2f3d206 100644 Binary files a/man/figures/README-ggsci-nejm-1.png and b/man/figures/README-ggsci-nejm-1.png differ diff --git a/man/figures/README-ggsci-npg-1.png b/man/figures/README-ggsci-npg-1.png index c83973a..b644d9b 100644 Binary files a/man/figures/README-ggsci-npg-1.png and b/man/figures/README-ggsci-npg-1.png differ diff --git a/man/figures/README-ggsci-observable-1.png b/man/figures/README-ggsci-observable-1.png index 2ef0b8d..6eb65c4 100644 Binary files a/man/figures/README-ggsci-observable-1.png and b/man/figures/README-ggsci-observable-1.png differ diff --git a/man/figures/README-ggsci-rickandmorty-1.png b/man/figures/README-ggsci-rickandmorty-1.png index aa1f718..90df9e7 100644 Binary files a/man/figures/README-ggsci-rickandmorty-1.png and b/man/figures/README-ggsci-rickandmorty-1.png differ diff --git a/man/figures/README-ggsci-simpsons-1.png b/man/figures/README-ggsci-simpsons-1.png index bdcc5d6..8532ae2 100644 Binary files a/man/figures/README-ggsci-simpsons-1.png and b/man/figures/README-ggsci-simpsons-1.png differ diff --git a/man/figures/README-ggsci-startrek-1.png b/man/figures/README-ggsci-startrek-1.png index ed6621e..9e4bbdd 100644 Binary files a/man/figures/README-ggsci-startrek-1.png and b/man/figures/README-ggsci-startrek-1.png differ diff --git a/man/figures/README-ggsci-tron-1.png b/man/figures/README-ggsci-tron-1.png index dce221b..3240888 100644 Binary files a/man/figures/README-ggsci-tron-1.png and b/man/figures/README-ggsci-tron-1.png differ diff --git a/man/figures/README-ggsci-tw3-1.png b/man/figures/README-ggsci-tw3-1.png index 88e3a17..43a0fb1 100644 Binary files a/man/figures/README-ggsci-tw3-1.png and b/man/figures/README-ggsci-tw3-1.png differ diff --git a/man/figures/README-ggsci-uchicago-1.png b/man/figures/README-ggsci-uchicago-1.png index 3e064ad..781da85 100644 Binary files a/man/figures/README-ggsci-uchicago-1.png and b/man/figures/README-ggsci-uchicago-1.png differ diff --git a/man/figures/README-ggsci-ucscgb-1.png b/man/figures/README-ggsci-ucscgb-1.png index 9370a6b..1c7f10c 100644 Binary files a/man/figures/README-ggsci-ucscgb-1.png and b/man/figures/README-ggsci-ucscgb-1.png differ diff --git a/man/scale_aaas.Rd b/man/scale_aaas.Rd index 78d1f91..f7271ac 100644 --- a/man/scale_aaas.Rd +++ b/man/scale_aaas.Rd @@ -26,25 +26,8 @@ See \code{alpha} in \code{\link[grDevices:rgb]{grDevices::rgb()}} for details.} See \code{\link[=pal_aaas]{pal_aaas()}} for details. } \examples{ -library("ggplot2") -data("diamonds") - -ggplot( - subset(diamonds, carat >= 2.2), - aes(x = table, y = price, colour = cut) -) + - geom_point(alpha = 0.7) + - geom_smooth(method = "loess", alpha = 0.1, size = 1, span = 1) + - theme_bw() + - scale_color_aaas() - -ggplot( - subset(diamonds, carat > 2.2 & depth > 55 & depth < 70), - aes(x = depth, fill = cut) -) + - geom_histogram(colour = "black", binwidth = 1, position = "dodge") + - theme_bw() + - scale_fill_aaas() +example_scatterplot() + scale_color_aaas() +example_barplot() + scale_fill_aaas() } \author{ Nan Xiao | \email{me@nanx.me} | \url{https://nanx.me} diff --git a/man/scale_bmj.Rd b/man/scale_bmj.Rd index 3470045..9d62e4f 100644 --- a/man/scale_bmj.Rd +++ b/man/scale_bmj.Rd @@ -26,25 +26,8 @@ See \code{alpha} in \code{\link[grDevices:rgb]{grDevices::rgb()}} for details.} See \code{\link[=pal_bmj]{pal_bmj()}} for details. } \examples{ -library("ggplot2") -data("diamonds") - -ggplot( - subset(diamonds, carat >= 2.2), - aes(x = table, y = price, colour = cut) -) + - geom_point(alpha = 0.7) + - geom_smooth(method = "loess", alpha = 0.1, size = 1, span = 1) + - theme_bw() + - scale_color_bmj() - -ggplot( - subset(diamonds, carat > 2.2 & depth > 55 & depth < 70), - aes(x = depth, fill = cut) -) + - geom_histogram(colour = "black", binwidth = 1, position = "dodge") + - theme_bw() + - scale_fill_bmj() +example_scatterplot() + scale_color_bmj() +example_barplot() + scale_fill_bmj() } \references{ \url{https://technology.bmj.com/living-style-guide/colour.html} diff --git a/man/scale_cosmic.Rd b/man/scale_cosmic.Rd index aa8cacb..7b8088a 100644 --- a/man/scale_cosmic.Rd +++ b/man/scale_cosmic.Rd @@ -44,25 +44,8 @@ See \code{alpha} in \code{\link[grDevices:rgb]{grDevices::rgb()}} for details.} See \code{\link[=pal_cosmic]{pal_cosmic()}} for details. } \examples{ -library("ggplot2") -data("diamonds") - -ggplot( - subset(diamonds, carat >= 2.2), - aes(x = table, y = price, colour = cut) -) + - geom_point(alpha = 0.7) + - geom_smooth(method = "loess", alpha = 0.1, size = 1, span = 1) + - theme_bw() + - scale_color_cosmic() - -ggplot( - subset(diamonds, carat > 2.2 & depth > 55 & depth < 70), - aes(x = depth, fill = cut) -) + - geom_histogram(colour = "black", binwidth = 1, position = "dodge") + - theme_bw() + - scale_fill_cosmic() +example_scatterplot() + scale_color_cosmic() +example_barplot() + scale_fill_cosmic() } \author{ Joshua H. Cook | \email{joshuacook0023@gmail.com} | diff --git a/man/scale_d3.Rd b/man/scale_d3.Rd index 7b4daac..f242ad6 100644 --- a/man/scale_d3.Rd +++ b/man/scale_d3.Rd @@ -42,23 +42,8 @@ See \code{alpha} in \code{\link[grDevices:rgb]{grDevices::rgb()}} for details.} See \code{\link[=pal_d3]{pal_d3()}} for details. } \examples{ -library("ggplot2") -data("diamonds") - -p1 <- ggplot( - subset(diamonds, carat >= 2.2), - aes(x = table, y = price, colour = cut) -) + - geom_point(alpha = 0.7) + - geom_smooth(method = "loess", alpha = 0.1, size = 1, span = 1) + - theme_bw() - -p2 <- ggplot( - subset(diamonds, carat > 2.2 & depth > 55 & depth < 70), - aes(x = depth, fill = cut) -) + - geom_histogram(colour = "black", binwidth = 1, position = "dodge") + - theme_bw() +p1 <- example_scatterplot() +p2 <- example_barplot() p1 + scale_color_d3() p2 + scale_fill_d3() diff --git a/man/scale_flatui.Rd b/man/scale_flatui.Rd index e7e5fcd..c7a94dd 100644 --- a/man/scale_flatui.Rd +++ b/man/scale_flatui.Rd @@ -41,23 +41,8 @@ See \code{alpha} in \code{\link[grDevices:rgb]{grDevices::rgb()}} for details.} See \code{\link[=pal_flatui]{pal_flatui()}} for details. } \examples{ -library("ggplot2") -data("diamonds") - -p1 <- ggplot( - subset(diamonds, carat >= 2.2), - aes(x = table, y = price, colour = cut) -) + - geom_point(alpha = 0.7) + - geom_smooth(method = "loess", alpha = 0.1, size = 1, span = 1) + - theme_bw() - -p2 <- ggplot( - subset(diamonds, carat > 2.2 & depth > 55 & depth < 70), - aes(x = depth, fill = cut) -) + - geom_histogram(colour = "black", binwidth = 1, position = "dodge") + - theme_bw() +p1 <- example_scatterplot() +p2 <- example_barplot() p1 + scale_color_flatui() p2 + scale_fill_flatui() diff --git a/man/scale_frontiers.Rd b/man/scale_frontiers.Rd index 6f864ca..1636b93 100644 --- a/man/scale_frontiers.Rd +++ b/man/scale_frontiers.Rd @@ -26,30 +26,18 @@ See \code{alpha} in \code{\link[grDevices:rgb]{grDevices::rgb()}} for details.} See \code{\link[=pal_frontiers]{pal_frontiers()}} for details. } \examples{ -library("ggplot2") -data("diamonds") - -ggplot( - subset(diamonds, carat >= 2.2), - aes(x = table, y = price, colour = cut) -) + - geom_point(alpha = 0.7) + - geom_smooth(method = "loess", alpha = 0.1, size = 1, span = 1) + - theme_dark() + - theme( - panel.background = element_rect(fill = "#2D2D2D"), - legend.key = element_rect(fill = "#2D2D2D") +example_scatterplot() + + ggplot2::theme_dark() + + ggplot2::theme( + panel.background = ggplot2::element_rect(fill = "#2D2D2D"), + legend.key = ggplot2::element_rect(fill = "#2D2D2D") ) + scale_color_frontiers() -ggplot( - subset(diamonds, carat > 2.2 & depth > 55 & depth < 70), - aes(x = depth, fill = cut) -) + - geom_histogram(colour = "black", binwidth = 1, position = "dodge") + - theme_dark() + - theme( - panel.background = element_rect(fill = "#2D2D2D") +example_barplot() + + ggplot2::theme_dark() + + ggplot2::theme( + panel.background = ggplot2::element_rect(fill = "#2D2D2D") ) + scale_fill_frontiers() } diff --git a/man/scale_futurama.Rd b/man/scale_futurama.Rd index 82692cd..00a8160 100644 --- a/man/scale_futurama.Rd +++ b/man/scale_futurama.Rd @@ -26,25 +26,8 @@ See \code{alpha} in \code{\link[grDevices:rgb]{grDevices::rgb()}} for details.} See \code{\link[=pal_futurama]{pal_futurama()}} for details. } \examples{ -library("ggplot2") -data("diamonds") - -ggplot( - subset(diamonds, carat >= 2.2), - aes(x = table, y = price, colour = cut) -) + - geom_point(alpha = 0.7) + - geom_smooth(method = "loess", alpha = 0.1, size = 1, span = 1) + - theme_bw() + - scale_color_futurama() - -ggplot( - subset(diamonds, carat > 2.2 & depth > 55 & depth < 70), - aes(x = depth, fill = cut) -) + - geom_histogram(colour = "black", binwidth = 1, position = "dodge") + - theme_bw() + - scale_fill_futurama() +example_scatterplot() + scale_color_futurama() +example_barplot() + scale_fill_futurama() } \author{ Nan Xiao | \email{me@nanx.me} | \url{https://nanx.me} diff --git a/man/scale_igv.Rd b/man/scale_igv.Rd index ac8229a..f36e0cc 100644 --- a/man/scale_igv.Rd +++ b/man/scale_igv.Rd @@ -29,31 +29,16 @@ See \code{alpha} in \code{\link[grDevices:rgb]{grDevices::rgb()}} for details.} See \code{\link[=pal_igv]{pal_igv()}} for details. } \examples{ -library("ggplot2") -data("diamonds") - -p1 <- ggplot( - subset(diamonds, carat >= 2.2), - aes(x = table, y = price, colour = cut) -) + - geom_point(alpha = 0.7) + - geom_smooth(method = "loess", alpha = 0.1, size = 1, span = 1) + - theme_bw() - -p2 <- ggplot( - subset(diamonds, carat > 2.2 & depth > 55 & depth < 70), - aes(x = depth, fill = cut) -) + - geom_histogram(colour = "black", binwidth = 1, position = "dodge") + - theme_bw() +p1 <- example_scatterplot() +p2 <- example_barplot() p1 + scale_color_igv() p2 + scale_fill_igv() -p1 + scale_colour_manual( +p1 + ggplot2::scale_colour_manual( values = rep(pal_igv("alternating")(2), times = 3) ) -p2 + scale_fill_manual( +p2 + ggplot2::scale_fill_manual( values = rep(pal_igv("alternating")(2), times = 3) ) } diff --git a/man/scale_jama.Rd b/man/scale_jama.Rd index 8490ff3..872220f 100644 --- a/man/scale_jama.Rd +++ b/man/scale_jama.Rd @@ -26,25 +26,8 @@ See \code{alpha} in \code{\link[grDevices:rgb]{grDevices::rgb()}} for details.} See \code{\link[=pal_jama]{pal_jama()}} for details. } \examples{ -library("ggplot2") -data("diamonds") - -ggplot( - subset(diamonds, carat >= 2.2), - aes(x = table, y = price, colour = cut) -) + - geom_point(alpha = 0.7) + - geom_smooth(method = "loess", alpha = 0.1, size = 1, span = 1) + - theme_bw() + - scale_color_jama() - -ggplot( - subset(diamonds, carat > 2.2 & depth > 55 & depth < 70), - aes(x = depth, fill = cut) -) + - geom_histogram(colour = "black", binwidth = 1, position = "dodge") + - theme_bw() + - scale_fill_jama() +example_scatterplot() + scale_color_jama() +example_barplot() + scale_fill_jama() } \author{ Nan Xiao | \email{me@nanx.me} | \url{https://nanx.me} diff --git a/man/scale_jco.Rd b/man/scale_jco.Rd index 95b2216..9a160e7 100644 --- a/man/scale_jco.Rd +++ b/man/scale_jco.Rd @@ -26,25 +26,8 @@ See \code{alpha} in \code{\link[grDevices:rgb]{grDevices::rgb()}} for details.} See \code{\link[=pal_jco]{pal_jco()}} for details. } \examples{ -library("ggplot2") -data("diamonds") - -ggplot( - subset(diamonds, carat >= 2.2), - aes(x = table, y = price, colour = cut) -) + - geom_point(alpha = 0.7) + - geom_smooth(method = "loess", alpha = 0.1, size = 1, span = 1) + - theme_bw() + - scale_color_jco() - -ggplot( - subset(diamonds, carat > 2.2 & depth > 55 & depth < 70), - aes(x = depth, fill = cut) -) + - geom_histogram(colour = "black", binwidth = 1, position = "dodge") + - theme_bw() + - scale_fill_jco() +example_scatterplot() + scale_color_jco() +example_barplot() + scale_fill_jco() } \author{ Nan Xiao | \email{me@nanx.me} | \url{https://nanx.me} diff --git a/man/scale_lancet.Rd b/man/scale_lancet.Rd index 267e353..f0078e0 100644 --- a/man/scale_lancet.Rd +++ b/man/scale_lancet.Rd @@ -26,25 +26,8 @@ See \code{alpha} in \code{\link[grDevices:rgb]{grDevices::rgb()}} for details.} See \code{\link[=pal_lancet]{pal_lancet()}} for details. } \examples{ -library("ggplot2") -data("diamonds") - -ggplot( - subset(diamonds, carat >= 2.2), - aes(x = table, y = price, colour = cut) -) + - geom_point(alpha = 0.7) + - geom_smooth(method = "loess", alpha = 0.1, size = 1, span = 1) + - theme_bw() + - scale_color_lancet() - -ggplot( - subset(diamonds, carat > 2.2 & depth > 55 & depth < 70), - aes(x = depth, fill = cut) -) + - geom_histogram(colour = "black", binwidth = 1, position = "dodge") + - theme_bw() + - scale_fill_lancet() +example_scatterplot() + scale_color_lancet() +example_barplot() + scale_fill_lancet() } \author{ Nan Xiao | \email{me@nanx.me} | \url{https://nanx.me} diff --git a/man/scale_locuszoom.Rd b/man/scale_locuszoom.Rd index d478f0f..40c8a1c 100644 --- a/man/scale_locuszoom.Rd +++ b/man/scale_locuszoom.Rd @@ -26,25 +26,8 @@ See \code{alpha} in \code{\link[grDevices:rgb]{grDevices::rgb()}} for details.} See \code{\link[=pal_locuszoom]{pal_locuszoom()}} for details. } \examples{ -library("ggplot2") -data("diamonds") - -ggplot( - subset(diamonds, carat >= 2.2), - aes(x = table, y = price, colour = cut) -) + - geom_point(alpha = 0.7) + - geom_smooth(method = "loess", alpha = 0.1, size = 1, span = 1) + - theme_bw() + - scale_color_locuszoom() - -ggplot( - subset(diamonds, carat > 2.2 & depth > 55 & depth < 70), - aes(x = depth, fill = cut) -) + - geom_histogram(colour = "black", binwidth = 1, position = "dodge") + - theme_bw() + - scale_fill_locuszoom() +example_scatterplot() + scale_color_locuszoom() +example_barplot() + scale_fill_locuszoom() } \author{ Nan Xiao | \email{me@nanx.me} | \url{https://nanx.me} diff --git a/man/scale_nejm.Rd b/man/scale_nejm.Rd index 483a6cd..44051ec 100644 --- a/man/scale_nejm.Rd +++ b/man/scale_nejm.Rd @@ -26,25 +26,8 @@ See \code{alpha} in \code{\link[grDevices:rgb]{grDevices::rgb()}} for details.} See \code{\link[=pal_nejm]{pal_nejm()}} for details. } \examples{ -library("ggplot2") -data("diamonds") - -ggplot( - subset(diamonds, carat >= 2.2), - aes(x = table, y = price, colour = cut) -) + - geom_point(alpha = 0.7) + - geom_smooth(method = "loess", alpha = 0.1, size = 1, span = 1) + - theme_bw() + - scale_color_nejm() - -ggplot( - subset(diamonds, carat > 2.2 & depth > 55 & depth < 70), - aes(x = depth, fill = cut) -) + - geom_histogram(colour = "black", binwidth = 1, position = "dodge") + - theme_bw() + - scale_fill_nejm() +example_scatterplot() + scale_color_nejm() +example_barplot() + scale_fill_nejm() } \author{ Nan Xiao | \email{me@nanx.me} | \url{https://nanx.me} diff --git a/man/scale_npg.Rd b/man/scale_npg.Rd index 1cee97e..698a93b 100644 --- a/man/scale_npg.Rd +++ b/man/scale_npg.Rd @@ -26,25 +26,8 @@ See \code{alpha} in \code{\link[grDevices:rgb]{grDevices::rgb()}} for details.} See \code{\link[=pal_npg]{pal_npg()}} for details. } \examples{ -library("ggplot2") -data("diamonds") - -ggplot( - subset(diamonds, carat >= 2.2), - aes(x = table, y = price, colour = cut) -) + - geom_point(alpha = 0.7) + - geom_smooth(method = "loess", alpha = 0.1, size = 1, span = 1) + - theme_bw() + - scale_color_npg() - -ggplot( - subset(diamonds, carat > 2.2 & depth > 55 & depth < 70), - aes(x = depth, fill = cut) -) + - geom_histogram(colour = "black", binwidth = 1, position = "dodge") + - theme_bw() + - scale_fill_npg() +example_scatterplot() + scale_color_npg() +example_barplot() + scale_fill_npg() } \author{ Nan Xiao | \email{me@nanx.me} | \url{https://nanx.me} diff --git a/man/scale_observable.Rd b/man/scale_observable.Rd index 40c67fc..5ff43ce 100644 --- a/man/scale_observable.Rd +++ b/man/scale_observable.Rd @@ -26,25 +26,8 @@ See \code{alpha} in \code{\link[grDevices:rgb]{grDevices::rgb()}} for details.} See \code{\link[=pal_observable]{pal_observable()}} for details. } \examples{ -library("ggplot2") -data("diamonds") - -ggplot( - subset(diamonds, carat >= 2.2), - aes(x = table, y = price, colour = cut) -) + - geom_point(alpha = 0.7) + - geom_smooth(method = "loess", alpha = 0.1, size = 1, span = 1) + - theme_bw() + - scale_color_observable() - -ggplot( - subset(diamonds, carat > 2.2 & depth > 55 & depth < 70), - aes(x = depth, fill = cut) -) + - geom_histogram(colour = "black", binwidth = 1, position = "dodge") + - theme_bw() + - scale_fill_observable() +example_scatterplot() + scale_color_observable() +example_barplot() + scale_fill_observable() } \references{ Pettiross J (2023). "Crafting data colors and staying on brand." diff --git a/man/scale_rickandmorty.Rd b/man/scale_rickandmorty.Rd index b144ac1..7bfee61 100644 --- a/man/scale_rickandmorty.Rd +++ b/man/scale_rickandmorty.Rd @@ -26,25 +26,8 @@ See \code{alpha} in \code{\link[grDevices:rgb]{grDevices::rgb()}} for details.} See \code{\link[=pal_rickandmorty]{pal_rickandmorty()}} for details. } \examples{ -library("ggplot2") -data("diamonds") - -ggplot( - subset(diamonds, carat >= 2.2), - aes(x = table, y = price, colour = cut) -) + - geom_point(alpha = 0.7) + - geom_smooth(method = "loess", alpha = 0.1, size = 1, span = 1) + - theme_bw() + - scale_color_rickandmorty() - -ggplot( - subset(diamonds, carat > 2.2 & depth > 55 & depth < 70), - aes(x = depth, fill = cut) -) + - geom_histogram(colour = "black", binwidth = 1, position = "dodge") + - theme_bw() + - scale_fill_rickandmorty() +example_scatterplot() + scale_color_rickandmorty() +example_barplot() + scale_fill_rickandmorty() } \author{ Nan Xiao | \email{me@nanx.me} | \url{https://nanx.me} diff --git a/man/scale_simpsons.Rd b/man/scale_simpsons.Rd index 0058bdf..39449c9 100644 --- a/man/scale_simpsons.Rd +++ b/man/scale_simpsons.Rd @@ -26,25 +26,8 @@ See \code{alpha} in \code{\link[grDevices:rgb]{grDevices::rgb()}} for details.} See \code{\link[=pal_simpsons]{pal_simpsons()}} for details. } \examples{ -library("ggplot2") -data("diamonds") - -ggplot( - subset(diamonds, carat >= 2.2), - aes(x = table, y = price, colour = cut) -) + - geom_point(alpha = 0.7) + - geom_smooth(method = "loess", alpha = 0.1, size = 1, span = 1) + - theme_bw() + - scale_color_simpsons() - -ggplot( - subset(diamonds, carat > 2.2 & depth > 55 & depth < 70), - aes(x = depth, fill = cut) -) + - geom_histogram(colour = "black", binwidth = 1, position = "dodge") + - theme_bw() + - scale_fill_simpsons() +example_scatterplot() + scale_color_simpsons() +example_barplot() + scale_fill_simpsons() } \author{ Nan Xiao | \email{me@nanx.me} | \url{https://nanx.me} diff --git a/man/scale_startrek.Rd b/man/scale_startrek.Rd index 431ecd9..338312a 100644 --- a/man/scale_startrek.Rd +++ b/man/scale_startrek.Rd @@ -26,25 +26,8 @@ See \code{alpha} in \code{\link[grDevices:rgb]{grDevices::rgb()}} for details.} See \code{\link[=pal_startrek]{pal_startrek()}} for details. } \examples{ -library("ggplot2") -data("diamonds") - -ggplot( - subset(diamonds, carat >= 2.2), - aes(x = table, y = price, colour = cut) -) + - geom_point(alpha = 0.7) + - geom_smooth(method = "loess", alpha = 0.1, size = 1, span = 1) + - theme_bw() + - scale_color_startrek() - -ggplot( - subset(diamonds, carat > 2.2 & depth > 55 & depth < 70), - aes(x = depth, fill = cut) -) + - geom_histogram(colour = "black", binwidth = 1, position = "dodge") + - theme_bw() + - scale_fill_startrek() +example_scatterplot() + scale_color_startrek() +example_barplot() + scale_fill_startrek() } \author{ Nan Xiao | \email{me@nanx.me} | \url{https://nanx.me} diff --git a/man/scale_tron.Rd b/man/scale_tron.Rd index 5b99bc5..d7b1a8d 100644 --- a/man/scale_tron.Rd +++ b/man/scale_tron.Rd @@ -26,30 +26,18 @@ See \code{alpha} in \code{\link[grDevices:rgb]{grDevices::rgb()}} for details.} See \code{\link[=pal_tron]{pal_tron()}} for details. } \examples{ -library("ggplot2") -data("diamonds") - -ggplot( - subset(diamonds, carat >= 2.2), - aes(x = table, y = price, colour = cut) -) + - geom_point(alpha = 0.7) + - geom_smooth(method = "loess", alpha = 0.1, size = 1, span = 1) + - theme_dark() + - theme( - panel.background = element_rect(fill = "#2D2D2D"), - legend.key = element_rect(fill = "#2D2D2D") +example_scatterplot() + + ggplot2::theme_dark() + + ggplot2::theme( + panel.background = ggplot2::element_rect(fill = "#2D2D2D"), + legend.key = ggplot2::element_rect(fill = "#2D2D2D") ) + scale_color_tron() -ggplot( - subset(diamonds, carat > 2.2 & depth > 55 & depth < 70), - aes(x = depth, fill = cut) -) + - geom_histogram(colour = "black", binwidth = 1, position = "dodge") + - theme_dark() + - theme( - panel.background = element_rect(fill = "#2D2D2D") +example_barplot() + + ggplot2::theme_dark() + + ggplot2::theme( + panel.background = ggplot2::element_rect(fill = "#2D2D2D") ) + scale_fill_tron() } diff --git a/man/scale_uchicago.Rd b/man/scale_uchicago.Rd index 9317cd0..af19611 100644 --- a/man/scale_uchicago.Rd +++ b/man/scale_uchicago.Rd @@ -30,23 +30,8 @@ See \code{alpha} in \code{\link[grDevices:rgb]{grDevices::rgb()}} for details.} See \code{\link[=pal_uchicago]{pal_uchicago()}} for details. } \examples{ -library("ggplot2") -data("diamonds") - -p1 <- ggplot( - subset(diamonds, carat >= 2.2), - aes(x = table, y = price, colour = cut) -) + - geom_point(alpha = 0.7) + - geom_smooth(method = "loess", alpha = 0.1, size = 1, span = 1) + - theme_bw() - -p2 <- ggplot( - subset(diamonds, carat > 2.2 & depth > 55 & depth < 70), - aes(x = depth, fill = cut) -) + - geom_histogram(colour = "black", binwidth = 1, position = "dodge") + - theme_bw() +p1 <- example_scatterplot() +p2 <- example_barplot() p1 + scale_color_uchicago() p2 + scale_fill_uchicago() diff --git a/man/scale_ucscgb.Rd b/man/scale_ucscgb.Rd index 2d83c26..de35ef1 100644 --- a/man/scale_ucscgb.Rd +++ b/man/scale_ucscgb.Rd @@ -26,25 +26,8 @@ See \code{alpha} in \code{\link[grDevices:rgb]{grDevices::rgb()}} for details.} See \code{\link[=pal_ucscgb]{pal_ucscgb()}} for details. } \examples{ -library("ggplot2") -data("diamonds") - -ggplot( - subset(diamonds, carat >= 2.2), - aes(x = table, y = price, colour = cut) -) + - geom_point(alpha = 0.7) + - geom_smooth(method = "loess", alpha = 0.1, size = 1, span = 1) + - theme_bw() + - scale_color_ucscgb() - -ggplot( - subset(diamonds, carat > 2.2 & depth > 55 & depth < 70), - aes(x = depth, fill = cut) -) + - geom_histogram(colour = "black", binwidth = 1, position = "dodge") + - theme_bw() + - scale_fill_ucscgb() +example_scatterplot() + scale_color_ucscgb() +example_barplot() + scale_fill_ucscgb() } \author{ Nan Xiao | \email{me@nanx.me} | \url{https://nanx.me} diff --git a/vignettes/ggsci.Rmd b/vignettes/ggsci.Rmd index 86390ae..1593486 100644 --- a/vignettes/ggsci.Rmd +++ b/vignettes/ggsci.Rmd @@ -162,27 +162,15 @@ summarized in the table below. We will use scatterplots with smooth curves, and bar plots to demonstrate the discrete color palettes in ggsci. -```{r} +```{r, message=FALSE, warning=FALSE} library("ggsci") library("ggplot2") library("gridExtra") +``` -data("diamonds") - -p1 <- ggplot( - subset(diamonds, carat >= 2.2), - aes(x = table, y = price, colour = cut) -) + - geom_point(alpha = 0.7) + - geom_smooth(method = "loess", alpha = 0.05, linewidth = 1, span = 1) + - theme_bw() - -p2 <- ggplot( - subset(diamonds, carat > 2.2 & depth > 55 & depth < 70), - aes(x = depth, fill = cut) -) + - geom_histogram(colour = "black", binwidth = 1, position = "dodge") + - theme_bw() +```{r} +p1 <- example_scatterplot() +p2 <- example_barplot() ``` ### NPG