Skip to content

Commit

Permalink
remove hole palette add kelly clarkson closes#3
Browse files Browse the repository at this point in the history
  • Loading branch information
johnmackintosh committed Mar 31, 2021
1 parent 5888389 commit d0f8dc6
Show file tree
Hide file tree
Showing 9 changed files with 85 additions and 87 deletions.
8 changes: 4 additions & 4 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export(beck_pal)
export(boo_pal)
export(bwitched_pal)
export(deeelite_pal)
export(hole_pal)
export(kelly_pal)
export(nodoubt_pal)
export(pop_palette)
export(rickroll_pal)
Expand All @@ -17,7 +17,7 @@ export(scale_color_beck)
export(scale_color_boo)
export(scale_color_bwitched)
export(scale_color_deeelite)
export(scale_color_hole)
export(scale_color_kelly)
export(scale_color_nodoubt)
export(scale_color_rickroll)
export(scale_color_sclub)
Expand All @@ -29,7 +29,7 @@ export(scale_colour_beck)
export(scale_colour_boo)
export(scale_colour_bwitched)
export(scale_colour_deeelite)
export(scale_colour_hole)
export(scale_colour_kelly)
export(scale_colour_nodoubt)
export(scale_colour_rickroll)
export(scale_colour_sclub)
Expand All @@ -41,7 +41,7 @@ export(scale_fill_beck)
export(scale_fill_boo)
export(scale_fill_bwitched)
export(scale_fill_deeelite)
export(scale_fill_hole)
export(scale_fill_kelly)
export(scale_fill_nodoubt)
export(scale_fill_rickroll)
export(scale_fill_sclub)
Expand Down
72 changes: 35 additions & 37 deletions R/hole_palette.R → R/kelly_palette.R
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))
}
}
6 changes: 3 additions & 3 deletions R/pop_palettes.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ pop_palettes <- list(
"#C89C93", "#572F58", "#71773E", "#446E80"),
deeelite = c("#365A4C", "#473D8C", "#90D044", "#DB616D", "#64403E",
"#5E3C80", "#9C8F42", "#8F2975", "#3A5A3C"),
hole = c("#67332C" ,"#904B32", "#A3663E", "#B98855", "#C9A466",
"#D4BB6F", "#738664", "#5C4966", "#6D4254"),
kelly = c("#ed5a7f" ,"#f0a93b", "#dbc83f", "#a4966a", "#60a984",
"#99715f", "#8b565e", "#696969", "#0b0c09"),
nodoubt = c("#2D4F81" ,"#5BB0BB", "#87A884", "#A93842", "#BA8E53",
"#7C5A72", "#ABBE7A", "#4D4574","#81A591"),
rickroll = c( "#1E3850" ,"#39315E", "#ECC639", "#E15368", "#E76A42" ,
Expand All @@ -38,7 +38,7 @@ pop_palettes <- list(
#'
#' @param name Name of palette. Select one:
#' \code{aqua}, \code{bangles}, \code{beck}, \code{boo},
#' \code{bwitched}, \code{deeelite},\code{hole}, \code{nodoubt},
#' \code{bwitched}, \code{deeelite},\code{kelly}, \code{nodoubt},
#' \code{rickroll},\code{sclub7}, \code{spice},\code{steps}
#'
#' @param n Number of colors desired.
Expand Down
Binary file modified man/figures/README-deeelite-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified man/figures/README-unnamed-chunk-2-7.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
30 changes: 15 additions & 15 deletions man/hole_pal.Rd → man/kelly_pal.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/pop_palette.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 12 additions & 12 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,18 @@ covers.

Featuring:

- Aqua
- Bangles
- Beck
- Betty Boo
- Aqua (Barbie Girl)
- Bangles (In Your Room)
- Beck (Midnite Vultures)
- Betty Boo (Where Are You Baby)
- B\*Witched
- Deee Lite
- Hole
- No Doubt
- Rick Astley
- S Club 7
- Spice Girls
- Steps
- Deee Lite (Groove is in the Heart)
- Kelly Clarkson (All I Ever Wanted)
- No Doubt Tragic Kingdom
- Rick Astley Never Gonna Give You Up (Remix)
- S Club 7 (S Club)
- Spice Girls (Spice Up Your Life)
- Steps (Step One)

## Why?

Expand Down Expand Up @@ -73,7 +73,7 @@ pop_palette("deeelite")
<img src="man/figures/README-boo-1.png" width="33%" /><img src="man/figures/README-boo-2.png" width="33%" /><img src="man/figures/README-boo-3.png" width="33%" />

``` r
pop_palette("hole")
pop_palette("kelly")
pop_palette("nodoubt")
pop_palette("rickroll")
```
Expand Down
30 changes: 15 additions & 15 deletions readme.rmd
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,18 @@ This is a collection of colour palettes based (mainly) on pop album covers.

Featuring:

- Aqua
- Bangles
- Beck
- Betty Boo
- B*Witched
- Deee Lite
- Hole
- No Doubt
- Rick Astley
- S Club 7
- Spice Girls
- Steps
- Aqua (Barbie Girl)
- Bangles (In Your Room)
- Beck (Midnite Vultures)
- Betty Boo (Where Are You Baby)
- B*Witched
- Deee Lite (Groove is in the Heart)
- Kelly Clarkson (All I Ever Wanted)
- No Doubt Tragic Kingdom
- Rick Astley Never Gonna Give You Up (Remix)
- S Club 7 (S Club)
- Spice Girls (Spice Up Your Life)
- Steps (Step One)

## Why?

Expand Down Expand Up @@ -79,7 +79,7 @@ pop_palette("deeelite")


```{r deeelite, fig.show = "hold",out.width = "33%"}
pop_palette("hole")
pop_palette("kelly")
pop_palette("nodoubt")
pop_palette("rickroll")
```
Expand Down Expand Up @@ -153,8 +153,8 @@ ggplot(data = data, aes(x = year, y = gdpPercap, fill = country)) +
geom_area(alpha = 0.8) +
theme_void() +
theme(legend.position = "none") +
scale_fill_hole() +
ggtitle(label = "scale_fill_hole")
scale_fill_kelly() +
ggtitle(label = "scale_fill_kelly")
ggplot(data = data, aes(x = year, y = gdpPercap, fill = country)) +
geom_area(alpha = 0.8) +
Expand Down

0 comments on commit d0f8dc6

Please sign in to comment.