dot-gg_scale_consistent: Use a colour scale from one plot in another

.gg_scale_consistentR Documentation

Use a colour scale from one plot in another

Description

Multiple factor levels with custom labels are difficult to sync between graphs if some levels are missing in the second plot. This copies the palette from one plot to another. It is sometimes the case that we want to reuse the fill from one plot as the color for another.

Usage

.gg_scale_consistent(
  plot,
  original_aesthetic = c("fill", "color"),
  target_aesthetic = original_aesthetic,
  ...
)

Arguments

plot

a ggplot with a colour scale to clone

original_aesthetic

the original aesthetic we are cloning (fill or color)

target_aesthetic

the aesthetic in the new plot we want to match.

...

Arguments passed on to ggplot2::scale_fill_manual

values

a set of aesthetic values to map data values to. The values will be matched in order (usually alphabetical) with the limits of the scale, or with breaks if provided. If this is a named vector, then the values will be matched based on the names instead. Data values that don't match will be given na.value.

aesthetics

Character string or vector of character strings listing the name(s) of the aesthetic(s) that this scale works with. This can be useful, for example, to apply colour settings to the colour and fill aesthetics at the same time, via aesthetics = c("colour", "fill").

breaks

One of:

  • NULL for no breaks

  • waiver() for the default breaks (the scale limits)

  • A character vector of breaks

  • A function that takes the limits as input and returns breaks as output

na.value

The aesthetic value to use for missing (NA) values


terminological/ggrrr documentation built on June 15, 2024, 6:35 a.m.