Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -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")),
Expand All @@ -23,6 +23,7 @@ Depends:
Imports:
ggplot2 (>= 2.0.0),
grDevices,
rlang,
scales
Suggests:
gridExtra,
Expand All @@ -31,5 +32,5 @@ Suggests:
rmarkdown
VignetteBuilder: knitr
Encoding: UTF-8
RoxygenNote: 7.3.2
RoxygenNote: 7.3.3
Roxygen: list(markdown = TRUE)
3 changes: 3 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -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)
Expand Down Expand Up @@ -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)
10 changes: 10 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
21 changes: 2 additions & 19 deletions R/discrete-aaas.R
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down
21 changes: 2 additions & 19 deletions R/discrete-bmj.R
Original file line number Diff line number Diff line change
Expand Up @@ -57,25 +57,8 @@ pal_bmj <- function(palette = c("default"), alpha = 1) {
#' <https://technology.bmj.com/living-style-guide/colour.html>
#'
#' @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()) {
Expand Down
21 changes: 2 additions & 19 deletions R/discrete-cosmic.R
Original file line number Diff line number Diff line change
Expand Up @@ -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, ...) {
Expand Down
19 changes: 2 additions & 17 deletions R/discrete-d3.R
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
19 changes: 2 additions & 17 deletions R/discrete-flatui.R
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
30 changes: 9 additions & 21 deletions R/discrete-frontiers.R
Original file line number Diff line number Diff line change
Expand Up @@ -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, ...) {
Expand Down
21 changes: 2 additions & 19 deletions R/discrete-futurama.R
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down
23 changes: 4 additions & 19 deletions R/discrete-igv.R
Original file line number Diff line number Diff line change
Expand Up @@ -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, ...) {
Expand Down
21 changes: 2 additions & 19 deletions R/discrete-jama.R
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down
21 changes: 2 additions & 19 deletions R/discrete-jco.R
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down
21 changes: 2 additions & 19 deletions R/discrete-lancet.R
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down
Loading
Loading