-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #19 from nrennie/fix-scale-name
Remove `scale_name` and fix argument names
- Loading branch information
Showing
43 changed files
with
581 additions
and
246 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
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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#' @keywords internal | ||
"_PACKAGE" | ||
|
||
## usethis namespace: start | ||
#' @importFrom lifecycle deprecated | ||
## usethis namespace: end | ||
NULL |
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
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
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,50 +1,64 @@ | ||
#' Plotting with PrettyCols palettes for colour ggplot2 | ||
#' @param name Name of Palette. Run \code{names(PrettyColsPalettes)} to view options. | ||
#' @param palette Name of Palette. Run \code{names(PrettyColsPalettes)} to view options. | ||
#' @param direction Sets order of colors. Default palette is 1. If direction is -1, | ||
#' palette color order is reversed | ||
#' @param legend_title Character string specifying legend title. Default `NULL`. | ||
#' @param legend_title `r lifecycle::badge("deprecated")` Deprecated in favour of `name`. | ||
#' @param ... Other arguments passed on to \code{\link[ggplot2]{discrete_scale}} | ||
#' @return A ggproto object defining a discrete colour scale for use with ggplot2. | ||
#' @examples | ||
#' library(ggplot2) | ||
#' ggplot(data=mtcars, aes(x=mpg, y=disp, color=factor(cyl))) + | ||
#' ggplot(data = mtcars, aes(x = mpg, y = disp, color = factor(cyl))) + | ||
#' geom_point() + | ||
#' scale_color_pretty_d("Bright") | ||
#' @export | ||
|
||
scale_color_pretty_d <- function(name, | ||
scale_color_pretty_d <- function(palette, | ||
direction = 1, | ||
legend_title = NULL, ...) { | ||
prettycols_disc <- function(name, direction = 1) { | ||
if (missing(palette)) { | ||
stop("Please use the 'palette' argument to define which colour palette you want to use.") | ||
} | ||
|
||
if (!is.null(legend_title)) { | ||
lifecycle::deprecate_soft( | ||
when = "1.1.0", | ||
what = "scale_color_pretty_d(legend_title)", | ||
details = "Please use `name` to set the legend title instead." | ||
) | ||
} | ||
|
||
prettycols_disc <- function(palette, direction = 1) { | ||
`%notin%` <- Negate(`%in%`) | ||
|
||
palette <- PrettyColsPalettes[[name]] | ||
palette_choice <- PrettyColsPalettes[[palette]] | ||
|
||
if (is.null(palette) || is.numeric(name)) { | ||
if (is.null(palette_choice) || is.numeric(palette)) { | ||
stop("Palette does not exist.") | ||
} | ||
|
||
if (direction %notin% c(1, -1)) { | ||
stop("Direction not valid. Please use 1 for standard palette or -1 for reversed palette.") | ||
} | ||
|
||
function(n) if (direction == 1) { | ||
palette[[1]][1:n] | ||
} else { | ||
rev(palette[[1]])[1:n] | ||
function(n) { | ||
if (direction == 1) { | ||
palette_choice[[1]][1:n] | ||
} else { | ||
rev(palette_choice[[1]])[1:n] | ||
} | ||
} | ||
|
||
} | ||
|
||
if (!is.null(legend_title)) { | ||
ggplot2::discrete_scale(name = legend_title, | ||
aesthetics = "colour", | ||
scale_name = "pretty_d", | ||
palette = prettycols_disc(name = name, direction = direction), ...) | ||
ggplot2::discrete_scale( | ||
name = legend_title, | ||
aesthetics = "colour", | ||
palette = prettycols_disc(palette = palette, direction = direction), ... | ||
) | ||
} else { | ||
ggplot2::discrete_scale(aesthetics = "colour", | ||
scale_name = "pretty_d", | ||
palette = prettycols_disc(name = name, direction = direction), ...) | ||
ggplot2::discrete_scale( | ||
aesthetics = "colour", | ||
palette = prettycols_disc(palette = palette, direction = direction), ... | ||
) | ||
} | ||
} |
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
Oops, something went wrong.