Skip to content

Commit

Permalink
Merge pull request #26 from nanxstats/scale-name
Browse files Browse the repository at this point in the history
Remove `scale_name` from `discrete_scale()` calls
  • Loading branch information
nanxstats authored Mar 17, 2024
2 parents 0b9645a + 2945fae commit 221c13b
Show file tree
Hide file tree
Showing 39 changed files with 287 additions and 224 deletions.
5 changes: 3 additions & 2 deletions R/continuous-gsea.R
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
rgb_gsea <- function(palette = c("default"), n = 12, alpha = 1, reverse = FALSE) {
palette <- match.arg(palette)

if (alpha > 1L | alpha <= 0L) stop("alpha must be in (0, 1]")
if (alpha > 1L || alpha <= 0L) stop("alpha must be in (0, 1]")

raw_cols <- ggsci_db$"gsea"[[palette]]
func_cols <- colorRamp(raw_cols, space = "Lab", interpolate = "spline")
Expand Down Expand Up @@ -97,7 +97,8 @@ pal_gsea <- function(palette = c("default"), n = 12, alpha = 1, reverse = FALSE)
#' aes(x = Var1, y = Var2, fill = value)
#' ) +
#' geom_tile(colour = "black", size = 0.3) +
#' theme_bw() + scale_fill_gsea()
#' theme_bw() +
#' scale_fill_gsea()
scale_color_gsea <- function(palette = c("default"), alpha = 1, reverse = FALSE, ...) {
palette <- match.arg(palette)
scale_color_gradientn(colours = rgb_gsea(palette, n = 512, alpha = alpha, reverse = reverse), ...)
Expand Down
45 changes: 23 additions & 22 deletions R/continuous-material.R
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,14 @@
#' show_col(pal_material("indigo")(10))
#' show_col(pal_material("indigo", n = 30, alpha = 0.6, reverse = TRUE)(30))
rgb_material <- function(
palette = c(
"red", "pink", "purple", "deep-purple", "indigo", "blue",
"light-blue", "cyan", "teal", "green", "light-green", "lime",
"yellow", "amber", "orange", "deep-orange", "brown", "grey", "blue-grey"
), n = 10, alpha = 1, reverse = FALSE) {
palette = c(
"red", "pink", "purple", "deep-purple", "indigo", "blue",
"light-blue", "cyan", "teal", "green", "light-green", "lime",
"yellow", "amber", "orange", "deep-orange", "brown", "grey", "blue-grey"
), n = 10, alpha = 1, reverse = FALSE) {
palette <- match.arg(palette)

if (alpha > 1L | alpha <= 0L) stop("alpha must be in (0, 1]")
if (alpha > 1L || alpha <= 0L) stop("alpha must be in (0, 1]")

raw_cols <- ggsci_db$"material"[[palette]]
func_cols <- colorRamp(raw_cols, space = "Lab", interpolate = "spline")
Expand Down Expand Up @@ -87,11 +87,11 @@ rgb_material <- function(
#' show_col(pal_material("indigo")(10))
#' show_col(pal_material("indigo", n = 30, alpha = 0.6, reverse = TRUE)(30))
pal_material <- function(
palette = c(
"red", "pink", "purple", "deep-purple", "indigo", "blue",
"light-blue", "cyan", "teal", "green", "light-green", "lime",
"yellow", "amber", "orange", "deep-orange", "brown", "grey", "blue-grey"
), n = 10, alpha = 1, reverse = FALSE) {
palette = c(
"red", "pink", "purple", "deep-purple", "indigo", "blue",
"light-blue", "cyan", "teal", "green", "light-green", "lime",
"yellow", "amber", "orange", "deep-orange", "brown", "grey", "blue-grey"
), n = 10, alpha = 1, reverse = FALSE) {
palette <- match.arg(palette)

alpha_cols <- rgb_material(palette, n, alpha, reverse)
Expand Down Expand Up @@ -127,13 +127,14 @@ pal_material <- function(
#' aes(x = Var1, y = Var2, fill = value)
#' ) +
#' geom_tile(colour = "black", size = 0.3) +
#' theme_bw() + scale_fill_material("blue-grey")
#' theme_bw() +
#' scale_fill_material("blue-grey")
scale_color_material <- function(
palette = c(
"red", "pink", "purple", "deep-purple", "indigo", "blue",
"light-blue", "cyan", "teal", "green", "light-green", "lime",
"yellow", "amber", "orange", "deep-orange", "brown", "grey", "blue-grey"
), alpha = 1, reverse = FALSE, ...) {
palette = c(
"red", "pink", "purple", "deep-purple", "indigo", "blue",
"light-blue", "cyan", "teal", "green", "light-green", "lime",
"yellow", "amber", "orange", "deep-orange", "brown", "grey", "blue-grey"
), alpha = 1, reverse = FALSE, ...) {
palette <- match.arg(palette)
scale_color_gradientn(
colours = rgb_material(
Expand All @@ -152,11 +153,11 @@ scale_colour_material <- scale_color_material
#' @importFrom ggplot2 scale_fill_gradientn
#' @rdname scale_material
scale_fill_material <- function(
palette = c(
"red", "pink", "purple", "deep-purple", "indigo", "blue",
"light-blue", "cyan", "teal", "green", "light-green", "lime",
"yellow", "amber", "orange", "deep-orange", "brown", "grey", "blue-grey"
), alpha = 1, reverse = FALSE, ...) {
palette = c(
"red", "pink", "purple", "deep-purple", "indigo", "blue",
"light-blue", "cyan", "teal", "green", "light-green", "lime",
"yellow", "amber", "orange", "deep-orange", "brown", "grey", "blue-grey"
), alpha = 1, reverse = FALSE, ...) {
palette <- match.arg(palette)
scale_fill_gradientn(
colours = rgb_material(
Expand Down
12 changes: 7 additions & 5 deletions R/discrete-aaas.R
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
pal_aaas <- function(palette = c("default"), alpha = 1) {
palette <- match.arg(palette)

if (alpha > 1L | alpha <= 0L) stop("alpha must be in (0, 1]")
if (alpha > 1L || alpha <= 0L) stop("alpha must be in (0, 1]")

raw_cols <- ggsci_db$"aaas"[[palette]]
raw_cols_rgb <- col2rgb(raw_cols)
Expand Down Expand Up @@ -64,17 +64,19 @@ pal_aaas <- function(palette = c("default"), alpha = 1) {
#' ) +
#' geom_point(alpha = 0.7) +
#' geom_smooth(method = "loess", alpha = 0.1, size = 1, span = 1) +
#' theme_bw() + scale_color_aaas()
#' 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()
#' theme_bw() +
#' scale_fill_aaas()
scale_color_aaas <- function(palette = c("default"), alpha = 1, ...) {
palette <- match.arg(palette)
discrete_scale("colour", "aaas", pal_aaas(palette, alpha), ...)
discrete_scale("colour", palette = pal_aaas(palette, alpha), ...)
}

#' @export scale_colour_aaas
Expand All @@ -86,5 +88,5 @@ scale_colour_aaas <- scale_color_aaas
#' @rdname scale_aaas
scale_fill_aaas <- function(palette = c("default"), alpha = 1, ...) {
palette <- match.arg(palette)
discrete_scale("fill", "aaas", pal_aaas(palette, alpha), ...)
discrete_scale("fill", palette = pal_aaas(palette, alpha), ...)
}
24 changes: 13 additions & 11 deletions R/discrete-cosmic.R
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@
#' show_col(pal_cosmic("signature_substitutions")(6))
#' show_col(pal_cosmic("signature_substitutions", alpha = 0.6)(6))
pal_cosmic <- function(
palette = c("hallmarks_light", "hallmarks_dark", "signature_substitutions"),
alpha = 1) {
palette = c("hallmarks_light", "hallmarks_dark", "signature_substitutions"),
alpha = 1) {
palette <- match.arg(palette)

if (alpha > 1L | alpha <= 0L) stop("alpha must be in (0, 1]")
if (alpha > 1L || alpha <= 0L) stop("alpha must be in (0, 1]")

raw_cols <- ggsci_db$"cosmic"[[palette]]
raw_cols_rgb <- col2rgb(raw_cols)
Expand Down Expand Up @@ -73,19 +73,21 @@ pal_cosmic <- function(
#' ) +
#' geom_point(alpha = 0.7) +
#' geom_smooth(method = "loess", alpha = 0.1, size = 1, span = 1) +
#' theme_bw() + scale_color_cosmic()
#' 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()
#' theme_bw() +
#' scale_fill_cosmic()
scale_color_cosmic <- function(
palette = c("hallmarks_light", "hallmarks_dark", "signature_substitutions"),
alpha = 1, ...) {
palette = c("hallmarks_light", "hallmarks_dark", "signature_substitutions"),
alpha = 1, ...) {
palette <- match.arg(palette)
discrete_scale("colour", "cosmic", pal_cosmic(palette, alpha), ...)
discrete_scale("colour", palette = pal_cosmic(palette, alpha), ...)
}

#' @export scale_colour_cosmic
Expand All @@ -96,8 +98,8 @@ scale_colour_cosmic <- scale_color_cosmic
#' @importFrom ggplot2 discrete_scale
#' @rdname scale_cosmic
scale_fill_cosmic <- function(
palette = c("hallmarks_light", "hallmarks_dark", "signature_substitutions"),
alpha = 1, ...) {
palette = c("hallmarks_light", "hallmarks_dark", "signature_substitutions"),
alpha = 1, ...) {
palette <- match.arg(palette)
discrete_scale("fill", "cosmic", pal_cosmic(palette, alpha), ...)
discrete_scale("fill", palette = pal_cosmic(palette, alpha), ...)
}
6 changes: 3 additions & 3 deletions R/discrete-d3.R
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
pal_d3 <- function(palette = c("category10", "category20", "category20b", "category20c"), alpha = 1) {
palette <- match.arg(palette)

if (alpha > 1L | alpha <= 0L) stop("alpha must be in (0, 1]")
if (alpha > 1L || alpha <= 0L) stop("alpha must be in (0, 1]")

raw_cols <- ggsci_db$"d3"[[palette]]
raw_cols_rgb <- col2rgb(raw_cols)
Expand Down Expand Up @@ -93,7 +93,7 @@ pal_d3 <- function(palette = c("category10", "category20", "category20b", "categ
#' p2 + scale_fill_d3(palette = "category20c")
scale_color_d3 <- function(palette = c("category10", "category20", "category20b", "category20c"), alpha = 1, ...) {
palette <- match.arg(palette)
discrete_scale("colour", "d3", pal_d3(palette, alpha), ...)
discrete_scale("colour", palette = pal_d3(palette, alpha), ...)
}

#' @export scale_colour_d3
Expand All @@ -105,5 +105,5 @@ scale_colour_d3 <- scale_color_d3
#' @rdname scale_d3
scale_fill_d3 <- function(palette = c("category10", "category20", "category20b", "category20c"), alpha = 1, ...) {
palette <- match.arg(palette)
discrete_scale("fill", "d3", pal_d3(palette, alpha), ...)
discrete_scale("fill", palette = pal_d3(palette, alpha), ...)
}
6 changes: 3 additions & 3 deletions R/discrete-flatui.R
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
pal_flatui <- function(palette = c("default", "flattastic", "aussie"), alpha = 1) {
palette <- match.arg(palette)

if (alpha > 1L | alpha <= 0L) stop("alpha must be in (0, 1]")
if (alpha > 1L || alpha <= 0L) stop("alpha must be in (0, 1]")

raw_cols <- ggsci_db$"flatui"[[palette]]
raw_cols_rgb <- col2rgb(raw_cols)
Expand Down Expand Up @@ -86,7 +86,7 @@ pal_flatui <- function(palette = c("default", "flattastic", "aussie"), alpha = 1
#' p2 + scale_fill_flatui(palette = "aussie")
scale_color_flatui <- function(palette = c("default", "flattastic", "aussie"), alpha = 1, ...) {
palette <- match.arg(palette)
discrete_scale("colour", "flatui", pal_flatui(palette, alpha), ...)
discrete_scale("colour", palette = pal_flatui(palette, alpha), ...)
}

#' @export scale_colour_flatui
Expand All @@ -98,5 +98,5 @@ scale_colour_flatui <- scale_color_flatui
#' @rdname scale_flatui
scale_fill_flatui <- function(palette = c("default", "flattastic", "aussie"), alpha = 1, ...) {
palette <- match.arg(palette)
discrete_scale("fill", "flatui", pal_flatui(palette, alpha), ...)
discrete_scale("fill", palette = pal_flatui(palette, alpha), ...)
}
12 changes: 7 additions & 5 deletions R/discrete-frontiers.R
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
pal_frontiers <- function(palette = c("default"), alpha = 1) {
palette <- match.arg(palette)

if (alpha > 1L | alpha <= 0L) stop("alpha must be in (0, 1]")
if (alpha > 1L || alpha <= 0L) stop("alpha must be in (0, 1]")

raw_cols <- ggsci_db$"frontiers"[[palette]]
raw_cols_rgb <- col2rgb(raw_cols)
Expand Down Expand Up @@ -60,7 +60,8 @@ pal_frontiers <- function(palette = c("default"), alpha = 1) {
#' ) +
#' geom_point(alpha = 0.7) +
#' geom_smooth(method = "loess", alpha = 0.1, size = 1, span = 1) +
#' theme_dark() + theme(
#' theme_dark() +
#' theme(
#' panel.background = element_rect(fill = "#2D2D2D"),
#' legend.key = element_rect(fill = "#2D2D2D")
#' ) +
Expand All @@ -71,13 +72,14 @@ pal_frontiers <- function(palette = c("default"), alpha = 1) {
#' aes(x = depth, fill = cut)
#' ) +
#' geom_histogram(colour = "black", binwidth = 1, position = "dodge") +
#' theme_dark() + theme(
#' theme_dark() +
#' theme(
#' panel.background = element_rect(fill = "#2D2D2D")
#' ) +
#' scale_fill_frontiers()
scale_color_frontiers <- function(palette = c("default"), alpha = 1, ...) {
palette <- match.arg(palette)
discrete_scale("colour", "frontiers", pal_frontiers(palette, alpha), ...)
discrete_scale("colour", palette = pal_frontiers(palette, alpha), ...)
}

#' @export scale_colour_frontiers
Expand All @@ -89,5 +91,5 @@ scale_colour_frontiers <- scale_color_frontiers
#' @rdname scale_frontiers
scale_fill_frontiers <- function(palette = c("default"), alpha = 1, ...) {
palette <- match.arg(palette)
discrete_scale("fill", "frontiers", pal_frontiers(palette, alpha), ...)
discrete_scale("fill", palette = pal_frontiers(palette, alpha), ...)
}
12 changes: 7 additions & 5 deletions R/discrete-futurama.R
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
pal_futurama <- function(palette = c("planetexpress"), alpha = 1) {
palette <- match.arg(palette)

if (alpha > 1L | alpha <= 0L) stop("alpha must be in (0, 1]")
if (alpha > 1L || alpha <= 0L) stop("alpha must be in (0, 1]")

raw_cols <- ggsci_db$"futurama"[[palette]]
raw_cols_rgb <- col2rgb(raw_cols)
Expand Down Expand Up @@ -62,17 +62,19 @@ pal_futurama <- function(palette = c("planetexpress"), alpha = 1) {
#' ) +
#' geom_point(alpha = 0.7) +
#' geom_smooth(method = "loess", alpha = 0.1, size = 1, span = 1) +
#' theme_bw() + scale_color_futurama()
#' 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()
#' theme_bw() +
#' scale_fill_futurama()
scale_color_futurama <- function(palette = c("planetexpress"), alpha = 1, ...) {
palette <- match.arg(palette)
discrete_scale("colour", "futurama", pal_futurama(palette, alpha), ...)
discrete_scale("colour", palette = pal_futurama(palette, alpha), ...)
}

#' @export scale_colour_futurama
Expand All @@ -84,5 +86,5 @@ scale_colour_futurama <- scale_color_futurama
#' @rdname scale_futurama
scale_fill_futurama <- function(palette = c("planetexpress"), alpha = 1, ...) {
palette <- match.arg(palette)
discrete_scale("fill", "futurama", pal_futurama(palette, alpha), ...)
discrete_scale("fill", palette = pal_futurama(palette, alpha), ...)
}
6 changes: 3 additions & 3 deletions R/discrete-igv.R
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
pal_igv <- function(palette = c("default", "alternating"), alpha = 1) {
palette <- match.arg(palette)

if (alpha > 1L | alpha <= 0L) stop("alpha must be in (0, 1]")
if (alpha > 1L || alpha <= 0L) stop("alpha must be in (0, 1]")

raw_cols <- ggsci_db$"igv"[[palette]]
raw_cols_rgb <- col2rgb(raw_cols)
Expand Down Expand Up @@ -89,7 +89,7 @@ pal_igv <- function(palette = c("default", "alternating"), alpha = 1) {
#' )
scale_color_igv <- function(palette = c("default", "alternating"), alpha = 1, ...) {
palette <- match.arg(palette)
discrete_scale("colour", "igv", pal_igv(palette, alpha), ...)
discrete_scale("colour", palette = pal_igv(palette, alpha), ...)
}

#' @export scale_colour_igv
Expand All @@ -101,5 +101,5 @@ scale_colour_igv <- scale_color_igv
#' @rdname scale_igv
scale_fill_igv <- function(palette = c("default", "alternating"), alpha = 1, ...) {
palette <- match.arg(palette)
discrete_scale("fill", "igv", pal_igv(palette, alpha), ...)
discrete_scale("fill", palette = pal_igv(palette, alpha), ...)
}
16 changes: 9 additions & 7 deletions R/discrete-jama.R
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
pal_jama <- function(palette = c("default"), alpha = 1) {
palette <- match.arg(palette)

if (alpha > 1L | alpha <= 0L) stop("alpha must be in (0, 1]")
if (alpha > 1L || alpha <= 0L) stop("alpha must be in (0, 1]")

raw_cols <- ggsci_db$"jama"[[palette]]
raw_cols_rgb <- col2rgb(raw_cols)
Expand Down Expand Up @@ -56,24 +56,26 @@ pal_jama <- 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_jama()
#'
#' 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()
#' theme_bw() +
#' scale_fill_jama()
scale_color_jama <- function(palette = c("default"), alpha = 1, ...) {
palette <- match.arg(palette)
discrete_scale("colour", "jama", pal_jama(palette, alpha), ...)
discrete_scale("colour", palette = pal_jama(palette, alpha), ...)
}

#' @export scale_colour_jama
Expand All @@ -85,5 +87,5 @@ scale_colour_jama <- scale_color_jama
#' @rdname scale_jama
scale_fill_jama <- function(palette = c("default"), alpha = 1, ...) {
palette <- match.arg(palette)
discrete_scale("fill", "jama", pal_jama(palette, alpha), ...)
discrete_scale("fill", palette = pal_jama(palette, alpha), ...)
}
Loading

0 comments on commit 221c13b

Please sign in to comment.