The default discrete colour scale.
Additional parameters passed on to the scale type,
One of the following:
NULL for the default palette stored in the theme.
a character vector of colours.
a single string naming a palette.
a palette function that when called with a single integer argument (the number of levels in the scale) returns the values that they should take.
The names of the aesthetics that this scale works with.
If na.translate = TRUE, what aesthetic value should the
missing values be displayed as? Does not apply to position scales
where NA is always placed at the far right.
The preferred mechanism for
setting the default palette is by using the theme. For example:
theme(palette.colour.discrete = "Okabe-Ito"). One of the following:
A character vector of color codes. The codes are used for a 'manual' color
scale as long as the number of codes exceeds the number of data levels
(if there are more levels than codes, scale_colour_hue()/scale_fill_hue()
are used to construct the default scale). If this is a named vector, then the color values
will be matched to levels based on the names of the vectors. Data values that
don't match will be set as na.value.
A list of character vectors of color codes. The minimum length vector that exceeds the number of data levels is chosen for the color scaling. This is useful if you want to change the color palette based on the number of levels.
A function that returns a discrete colour/fill scale (e.g., scale_fill_hue(),
scale_fill_brewer(), etc).
The discrete colour scales section of the online ggplot2 book.
# A standard plot
p <- ggplot(mpg, aes(displ, hwy, colour = class)) +
geom_point()
# You can use the scale to give a palette directly
p + scale_colour_discrete(palette = scales::pal_brewer(palette = "Dark2"))
# The default colours are encoded into the theme
p + theme(palette.colour.discrete = scales::pal_grey())
# You can globally set default colour palette via the theme
old <- update_theme(palette.colour.discrete = scales::pal_viridis())
# Plot now shows new global default
p
# Restoring the previous theme
theme_set(old)