-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
46db03d
commit cbc0cc7
Showing
7 changed files
with
327 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,20 @@ | ||
# Generated by roxygen2: do not edit by hand | ||
|
||
S3method(print,palette) | ||
export(aqua_pal) | ||
export(pop_palette) | ||
export(print_pal) | ||
export(scale_color_aqua) | ||
export(scale_colour_aqua) | ||
export(scale_fill_aqua) | ||
importFrom(ggplot2,discrete_scale) | ||
importFrom(ggplot2,scale_color_gradientn) | ||
importFrom(ggplot2,scale_fill_gradientn) | ||
importFrom(glue,glue) | ||
importFrom(grDevices,colorRampPalette) | ||
importFrom(grDevices,rgb) | ||
importFrom(graphics,image) | ||
importFrom(graphics,par) | ||
importFrom(graphics,rect) | ||
importFrom(graphics,text) | ||
importFrom(scales,manual_pal) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
aqua_palette <- c( | ||
"#B46843", "#C0AB45", "#5F8841", "#32956F", "#31A6B3", | ||
"#1EA8CF", "#2A638E", "#834583", "#BB3855" | ||
) | ||
|
||
#' @title aqua palette | ||
#' @description aqua palette | ||
#' @inheritDotParams ggplot2::discrete_scale | ||
#' @param n number of colors | ||
#' @param type discrete or continuous | ||
#' @param reverse reverse order, Default: FALSE | ||
#' @rdname aqua_pal | ||
#' @examples | ||
#' library(scales) | ||
#' show_col(aqua_pal()(9)) | ||
#' @export | ||
#' @importFrom scales manual_pal | ||
#' @importFrom glue glue | ||
#' @importFrom grDevices colorRampPalette | ||
|
||
aqua_pal <- function(n, type = c("discrete", "continuous"), | ||
reverse = FALSE){ | ||
aqua <- aqua_palette | ||
|
||
if (reverse == TRUE) { | ||
aqua <- rev(aqua) | ||
} | ||
|
||
if (missing(n)) { | ||
n <- length(aqua) | ||
} | ||
|
||
type <- match.arg(type) | ||
|
||
if (type == "discrete" && n > length(aqua)) { | ||
stop(glue::glue("Palette does not have {n} colors, maximum is {length(aqua)}!")) | ||
} | ||
|
||
aqua <- switch(type, | ||
continuous = grDevices::colorRampPalette(aqua)(n), | ||
discrete = aqua[1:n]) | ||
|
||
aqua <- scales::manual_pal(aqua) | ||
|
||
return(aqua) | ||
} | ||
|
||
#' @title scale_color_aqua | ||
#' @rdname aqua_pal | ||
#' @export | ||
#' @examples | ||
#' | ||
#' library(ggplot2) | ||
#' ggplot(airquality, aes(x = Day, y = Temp, | ||
#' group = as.factor(Month), color = as.factor(Month))) + | ||
#' geom_point(size = 2.5) + | ||
#' scale_color_aqua() | ||
#' @importFrom ggplot2 discrete_scale scale_color_gradientn | ||
|
||
scale_color_aqua <- function(n, type = "discrete", | ||
reverse = FALSE, ...){ | ||
if (type == "discrete") { | ||
ggplot2::discrete_scale("color", "aqua", | ||
aqua_pal(n = n, type = type, | ||
reverse = reverse), ...) | ||
} else { | ||
ggplot2::scale_color_gradientn(colors = aqua_pal(n = n, type = type, | ||
reverse = reverse)(256)) | ||
} | ||
} | ||
|
||
#' @title scale_colour_aqua | ||
#' @rdname aqua_pal | ||
#' @export | ||
#' @examples | ||
#' | ||
#' ggplot(airquality, aes(x = Day, y = Temp, | ||
#' group = as.factor(Month), color = as.factor(Month))) + | ||
#' geom_point(size = 2.5) + | ||
#' scale_colour_aqua() | ||
#' @importFrom ggplot2 discrete_scale scale_color_gradientn | ||
|
||
scale_colour_aqua <- scale_color_aqua | ||
|
||
#' @title scale_fill_aqua | ||
#' @rdname aqua_pal | ||
#' @export | ||
#' @examples | ||
#' | ||
#' ggplot(mpg, aes(displ)) + | ||
#' geom_histogram(aes(fill = class), | ||
#' col = "black", size = 0.1) + | ||
#' scale_fill_aqua() | ||
#' @importFrom ggplot2 discrete_scale scale_fill_gradientn | ||
|
||
scale_fill_aqua <- function(n, type = "discrete", | ||
reverse = FALSE, ...){ | ||
if (type == "discrete") { | ||
ggplot2::discrete_scale("fill", "aqua", | ||
aqua_pal(n = n, type = type, | ||
reverse = reverse), ...) | ||
} else { | ||
ggplot2::scale_fill_gradientn(colors = aqua_pal(n = n, type = type, | ||
reverse = reverse)(256)) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.