Skip to contents

Named convenience constructors for popular palettes, easing migration from ggplot2. They are thin wrappers over the palette = argument of scale_color_continuous() / scale_color_discrete() (any grDevices::hcl.colors() name works there directly).

Usage

scale_color_viridis_c(
  plot,
  option = "viridis",
  breaks = NULL,
  labels = NULL,
  name = NULL,
  limits = NULL,
  na.value = NULL,
  oob = NULL
)

scale_color_viridis_d(
  plot,
  option = "viridis",
  breaks = NULL,
  labels = NULL,
  name = NULL,
  drop = TRUE
)

scale_fill_viridis_c(
  plot,
  option = "viridis",
  breaks = NULL,
  labels = NULL,
  name = NULL,
  limits = NULL,
  na.value = NULL,
  oob = NULL
)

scale_fill_viridis_d(
  plot,
  option = "viridis",
  breaks = NULL,
  labels = NULL,
  name = NULL,
  drop = TRUE
)

scale_color_brewer(
  plot,
  palette = "Blues",
  breaks = NULL,
  labels = NULL,
  name = NULL,
  type = "seq",
  direction = 1,
  drop = TRUE
)

scale_fill_brewer(
  plot,
  palette = "Blues",
  breaks = NULL,
  labels = NULL,
  name = NULL,
  type = "seq",
  direction = 1,
  drop = TRUE
)

scale_color_distiller(
  plot,
  palette = "Blues",
  breaks = NULL,
  labels = NULL,
  name = NULL,
  type = "seq",
  direction = -1,
  limits = NULL,
  na.value = NULL,
  oob = NULL
)

scale_fill_distiller(
  plot,
  palette = "Blues",
  breaks = NULL,
  labels = NULL,
  name = NULL,
  type = "seq",
  direction = -1,
  limits = NULL,
  na.value = NULL,
  oob = NULL
)

scale_colour_viridis_c(
  plot,
  option = "viridis",
  breaks = NULL,
  labels = NULL,
  name = NULL,
  limits = NULL,
  na.value = NULL,
  oob = NULL
)

scale_colour_viridis_d(
  plot,
  option = "viridis",
  breaks = NULL,
  labels = NULL,
  name = NULL,
  drop = TRUE
)

scale_colour_brewer(
  plot,
  palette = "Blues",
  breaks = NULL,
  labels = NULL,
  name = NULL,
  type = "seq",
  direction = 1,
  drop = TRUE
)

scale_colour_distiller(
  plot,
  palette = "Blues",
  breaks = NULL,
  labels = NULL,
  name = NULL,
  type = "seq",
  direction = -1,
  limits = NULL,
  na.value = NULL,
  oob = NULL
)

Arguments

plot

A PlotSpec.

option

Which viridis map (see above).

name, breaks, labels

As for scale_color_continuous().

limits, oob, na.value

For the continuous scales (_viridis_c(), _distiller()), the mapped data range c(min, max), what to do with values outside it ("censor", "squish", "keep" or a function; NULL, the default, squishes) and the colour of missing values, as for scale_color_continuous().

drop

For the discrete scales, drop factor levels that no row uses (default TRUE, as in ggplot2): they get no legend key and no palette entry, so the colours go to the levels that remain. FALSE keeps every level. limits overrides it.

palette

A ColorBrewer palette name or index (see above), or a grDevices::hcl.colors() palette name.

type

When palette is a number, which ColorBrewer family it indexes: "seq" (sequential), "div" (diverging) or "qual" (qualitative).

direction

1 keeps a ColorBrewer palette's order, -1 reverses it. scale_*_distiller() defaults to -1, as in ggplot2, so high values are light. Ignored for non-ColorBrewer palette names.

Value

The modified PlotSpec.

Details

  • scale_*_viridis_c() / scale_*_viridis_d() — the perceptually-uniform, colour-vision-deficient-safe viridis maps, continuous (_c) or discrete (_d). option picks the map: "viridis", "plasma", "inferno", "cividis", "rocket", or "mako" (unknown options fall back to viridis).

  • scale_*_brewer() — a discrete ColorBrewer palette (sequential, diverging or qualitative, via scales::pal_brewer()); scale_*_distiller() — the same palette's 7-class ramp interpolated for continuous data. palette is a ColorBrewer name ("Set1", "Dark2", "Paired", "Blues", "RdBu", "Spectral", ...; matched ignoring case, spaces and punctuation, so "Set 2" is "Set2") or an index into the palettes of type. Any other grDevices::hcl.colors() name (e.g. "Batlow") is passed through unchanged, as by scale_color_discrete() / scale_color_continuous().

Examples

vplot(mtcars) |> mark_point(x = wt, y = mpg, color = hp) |> scale_color_viridis_c()

vplot(mtcars) |>
  mark_point(x = wt, y = mpg, color = factor(cyl)) |>
  scale_color_brewer(palette = "Set1")

vplot(mtcars) |>
  mark_point(x = wt, y = mpg, color = hp) |>
  scale_color_distiller(palette = "Spectral")