-
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.
remove hole palette add kelly clarkson closes#3
- Loading branch information
1 parent
5888389
commit d0f8dc6
Showing
9 changed files
with
85 additions
and
87 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,106 +1,104 @@ | ||
hole_palette <- c( | ||
"#67332C" ,"#904B32", "#A3663E", "#B98855", "#C9A466", | ||
"#D4BB6F", "#738664", "#5C4966", "#6D4254" | ||
) | ||
kelly_palette <- c("#ed5a7f" ,"#f0a93b", "#dbc83f", "#a4966a", "#60a984", | ||
"#99715f", "#8b565e", "#696969", "#0b0c09") | ||
|
||
#' @title hole palette | ||
#' @description hole palette | ||
#' @title kelly palette | ||
#' @description kelly palette | ||
#' @inheritDotParams ggplot2::discrete_scale | ||
#' @param n number of colors | ||
#' @param type discrete or continuous | ||
#' @param reverse reverse order, Default: FALSE | ||
#' @rdname hole_pal | ||
#' @rdname kelly_pal | ||
#' @examples | ||
#' library(scales) | ||
#' show_col(hole_pal()(9)) | ||
#' show_col(kelly_pal()(9)) | ||
#' @export | ||
#' @importFrom scales manual_pal | ||
#' @importFrom glue glue | ||
#' @importFrom grDevices colorRampPalette | ||
|
||
hole_pal <- function(n, type = c("discrete", "continuous"), | ||
kelly_pal <- function(n, type = c("discrete", "continuous"), | ||
reverse = FALSE){ | ||
hole <- hole_palette | ||
kelly <- kelly_palette | ||
|
||
if (reverse == TRUE) { | ||
hole <- rev(hole) | ||
kelly <- rev(kelly) | ||
} | ||
|
||
if (missing(n)) { | ||
n <- length(hole) | ||
n <- length(kelly) | ||
} | ||
|
||
type <- match.arg(type) | ||
|
||
if (type == "discrete" && n > length(hole)) { | ||
stop(glue::glue("Palette does not have {n} colors, maximum is {length(hole)}!")) | ||
if (type == "discrete" && n > length(kelly)) { | ||
stop(glue::glue("Palette does not have {n} colors, maximum is {length(kelly)}!")) | ||
} | ||
|
||
hole <- switch(type, | ||
continuous = grDevices::colorRampPalette(hole)(n), | ||
discrete = hole[1:n]) | ||
kelly <- switch(type, | ||
continuous = grDevices::colorRampPalette(kelly)(n), | ||
discrete = kelly[1:n]) | ||
|
||
hole <- scales::manual_pal(hole) | ||
kelly <- scales::manual_pal(kelly) | ||
|
||
return(hole) | ||
return(kelly) | ||
} | ||
|
||
#' @title scale_color_hole | ||
#' @rdname hole_pal | ||
#' @title scale_color_kelly | ||
#' @rdname kelly_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_hole() | ||
#' scale_color_kelly() | ||
#' @importFrom ggplot2 discrete_scale scale_color_gradientn | ||
|
||
scale_color_hole <- function(n, type = "discrete", | ||
scale_color_kelly <- function(n, type = "discrete", | ||
reverse = FALSE, ...){ | ||
if (type == "discrete") { | ||
ggplot2::discrete_scale("color", "hole", | ||
hole_pal(n = n, type = type, | ||
ggplot2::discrete_scale("color", "kelly", | ||
kelly_pal(n = n, type = type, | ||
reverse = reverse), ...) | ||
} else { | ||
ggplot2::scale_color_gradientn(colors = hole_pal(n = n, type = type, | ||
ggplot2::scale_color_gradientn(colors = kelly_pal(n = n, type = type, | ||
reverse = reverse)(256)) | ||
} | ||
} | ||
|
||
#' @title scale_colour_hole | ||
#' @rdname hole_pal | ||
#' @title scale_colour_kelly | ||
#' @rdname kelly_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_hole() | ||
#' scale_colour_kelly() | ||
#' @importFrom ggplot2 discrete_scale scale_color_gradientn | ||
|
||
scale_colour_hole <- scale_color_hole | ||
scale_colour_kelly <- scale_color_kelly | ||
|
||
#' @title scale_fill_hole | ||
#' @rdname hole_pal | ||
#' @title scale_fill_kelly | ||
#' @rdname kelly_pal | ||
#' @export | ||
#' @examples | ||
#' | ||
#' ggplot(mpg, aes(displ)) + | ||
#' geom_histogram(aes(fill = class), | ||
#' col = "black", size = 0.1) + | ||
#' scale_fill_hole() | ||
#' scale_fill_kelly() | ||
#' @importFrom ggplot2 discrete_scale scale_fill_gradientn | ||
|
||
scale_fill_hole <- function(n, type = "discrete", | ||
scale_fill_kelly <- function(n, type = "discrete", | ||
reverse = FALSE, ...){ | ||
if (type == "discrete") { | ||
ggplot2::discrete_scale("fill", "hole", | ||
hole_pal(n = n, type = type, | ||
ggplot2::discrete_scale("fill", "kelly", | ||
kelly_pal(n = n, type = type, | ||
reverse = reverse), ...) | ||
} else { | ||
ggplot2::scale_fill_gradientn(colors = hole_pal(n = n, type = type, | ||
ggplot2::scale_fill_gradientn(colors = kelly_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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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.
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