Skip to content

Commit 3a030f3

Browse files
committed
Tidy up documentation
1 parent 6bbcb99 commit 3a030f3

File tree

2 files changed

+52
-34
lines changed

2 files changed

+52
-34
lines changed

R/scale-hue.r

Lines changed: 26 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,9 @@ scale_fill_hue <- function(..., h = c(0, 360) + 15, c = 100, l = 65, h.start = 0
6666

6767
#' Discrete colour scales
6868
#'
69-
#' Colour scales for discrete data default to the values of the `ggplot2.discrete.fill`
70-
#' and `ggplot2.discrete.colour` options. By default these scales attempt to use
71-
#' a colour-blind safe (or a custom) palette, but if the number of levels is
72-
#' large, they fallback to [scale_fill_hue()]/[scale_colour_hue()].
69+
#' The default discrete colour scale. Defaults to [scale_fill_hue()]/[scale_fill_brewer()]
70+
#' unless `type` (which defaults to the `ggplot2.discrete.fill`/`ggplot2.discrete.colour` options)
71+
#' is specified.
7372
#'
7473
#' @param ... Additional parameters passed on to the scale type,
7574
#' @param type One of the following:
@@ -90,22 +89,32 @@ scale_fill_hue <- function(..., h = c(0, 360) + 15, c = 100, l = 65, h.start = 0
9089
#' ggplot(mpg, aes(cty, colour = factor({{var}}), fill = factor({{var}}))) +
9190
#' geom_density(alpha = 0.2)
9291
#' }
93-
#' # The default color scale for three levels
92+
#'
93+
#' # The default, scale_fill_hue(), is not colour-blind safe
9494
#' cty_by_var(class)
9595
#'
96-
#' # Define custom palettes for when there are 1-2, 3, or 4-6 levels
97-
#' opts <- options(
98-
#' ggplot2.discrete.fill = list(
99-
#' c("skyblue", "orange"),
100-
#' RColorBrewer::brewer.pal(3, "Set2"),
101-
#' RColorBrewer::brewer.pal(6, "Accent")
102-
#' )
96+
#' # (Temporarily) set the default to Okabe-Ito (which is colour-blind safe)
97+
#' okabe <- c("#E69F00", "#56B4E9", "#009E73", "#F0E442", "#0072B2", "#D55E00", "#CC79A7")
98+
#' withr::with_options(
99+
#' list(ggplot2.discrete.fill = okabe),
100+
#' print(cty_by_var(class))
103101
#' )
104-
#' cty_by_var(year)
105-
#' cty_by_var(drv)
106-
#' cty_by_var(fl)
107-
#' cty_by_var(class)
108-
#' options(opts)
102+
#'
103+
#' # Define a collection of palettes to alter the default based on number of levels to encode
104+
#' discrete_palettes <- list(
105+
#' c("skyblue", "orange"),
106+
#' RColorBrewer::brewer.pal(3, "Set2"),
107+
#' RColorBrewer::brewer.pal(6, "Accent")
108+
#' )
109+
#' withr::with_options(
110+
#' list(ggplot2.discrete.fill = discrete_palettes), {
111+
#' # 1st palette is used when there 1-2 levels (e.g., year)
112+
#' print(cty_by_var(year))
113+
#' # 2nd palette is used when there are 3 levels
114+
#' print(cty_by_var(drv))
115+
#' # 3rd palette is used when there are 4-6 levels
116+
#' print(cty_by_var(fl))
117+
#' })
109118
#'
110119
scale_colour_discrete <- function(..., type = getOption("ggplot2.discrete.colour", getOption("ggplot2.discrete.fill"))) {
111120
# TODO: eventually `type` should default to a set of colour-blind safe color codes (e.g. Okabe-Ito)

man/scale_colour_discrete.Rd

Lines changed: 26 additions & 17 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)