Skip to content

Improve color scale documentation #4450

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Apr 28, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions R/scale-colour.r
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@
#' Colour scales for continuous data default to the values of the
#' `ggplot2.continuous.colour` and `ggplot2.continuous.fill` options. These
#' [options()] default to `"gradient"` (i.e., [scale_colour_gradient()] and
#' [scale_fill_gradient()])
#' [scale_fill_gradient()]). Note that both continuous and binned scales
#' are configured with the same options values. In other words,
#' the option `ggplot2.continuous.colour` controls the behavior of both
#' `scale_colour_continuous()` and `scale_colour_binned()`. To manually set
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't it be more correct to say that the binned scale falls back to ggplot2.continuous.colour if ggplot2.binned.colour is not set?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, yes, for some reason I missed this.

#' the colors of the scale, consider using [scale_colour_gradient()] or
#' [scale_colour_steps()].
#'
#' @param ... Additional parameters passed on to the scale type
#' @param type One of the following:
Expand All @@ -13,7 +18,7 @@
#' @seealso [scale_colour_gradient()], [scale_colour_viridis_c()],
#' [scale_colour_steps()], [scale_colour_viridis_b()], [scale_fill_gradient()],
#' [scale_fill_viridis_c()], [scale_fill_steps()], and [scale_fill_viridis_b()]
#' @export
#' @family colour scales
#' @rdname scale_colour_continuous
#' @section Color Blindness:
#' Many color palettes derived from RGB combinations (like the "rainbow" color
Expand All @@ -40,6 +45,10 @@
#' # The above are equivalent to
#' v + scale_fill_gradient()
#' v + scale_fill_viridis_c()
#'
#' # To make a binned version of this plot
#' v + scale_fill_binned(type = "viridis")
#' @export
scale_colour_continuous <- function(...,
type = getOption("ggplot2.continuous.colour", default = "gradient")) {
if (is.function(type)) {
Expand Down Expand Up @@ -70,7 +79,6 @@ scale_fill_continuous <- function(...,

#' @export
#' @rdname scale_colour_continuous
#' @usage NULL
scale_colour_binned <- function(...,
type = getOption("ggplot2.binned.colour", default = getOption("ggplot2.continuous.colour", default = "gradient"))) {
if (is.function(type)) {
Expand All @@ -86,7 +94,6 @@ scale_colour_binned <- function(...,

#' @export
#' @rdname scale_colour_continuous
#' @usage NULL
scale_fill_binned <- function(...,
type = getOption("ggplot2.binned.fill", default = getOption("ggplot2.continuous.fill", default = "gradient"))) {
if (is.function(type)) {
Expand Down
5 changes: 3 additions & 2 deletions R/scale-gradient.r
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
#'
#' `scale_*_gradient` creates a two colour gradient (low-high),
#' `scale_*_gradient2` creates a diverging colour gradient (low-mid-high),
#' `scale_*_gradientn` creates a n-colour gradient.
#' `scale_*_gradientn` creates a n-colour gradient. For binned variants of
#' these scales, see the [color steps][scale_colour_steps] scales.
#'
#' Default colours are generated with \pkg{munsell} and
#' `mnsl(c("2.5PB 2/4", "2.5PB 7/10"))`. Generally, for continuous
Expand All @@ -17,7 +18,7 @@
#' colour bar, or `"legend"` for discrete colour legend.
#' @inheritDotParams continuous_scale -na.value -guide -aesthetics
#' @seealso [scales::seq_gradient_pal()] for details on underlying
#' palette
#' palette, [scale_colour_steps()] for binned variants of these scales.
#' @family colour scales
#' @rdname scale_gradient
#' @export
Expand Down
2 changes: 1 addition & 1 deletion R/scale-steps.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#' @inheritDotParams binned_scale -aesthetics -scale_name -palette -na.value -guide -rescaler
#'
#' @seealso [scales::seq_gradient_pal()] for details on underlying
#' palette
#' palette, [scale_colour_gradient()] for continuous scales without binning.
#' @family colour scales
#' @export
#' @examples
Expand Down
1 change: 1 addition & 0 deletions man/scale_alpha.Rd

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

1 change: 1 addition & 0 deletions man/scale_brewer.Rd

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

32 changes: 31 additions & 1 deletion man/scale_colour_continuous.Rd

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

6 changes: 4 additions & 2 deletions man/scale_gradient.Rd

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

3 changes: 1 addition & 2 deletions man/scale_grey.Rd

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

1 change: 1 addition & 0 deletions man/scale_hue.Rd

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

3 changes: 2 additions & 1 deletion man/scale_steps.Rd

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