scale_colour_discrete | R Documentation |
The default discrete colour scale. Defaults to scale_fill_hue()
/scale_fill_brewer()
unless type
(which defaults to the ggplot2.discrete.fill
/ggplot2.discrete.colour
options)
is specified.
scale_colour_discrete(
...,
palette = NULL,
aesthetics = "colour",
na.value = "grey50",
type = getOption("ggplot2.discrete.colour")
)
scale_fill_discrete(
...,
palette = NULL,
aesthetics = "fill",
na.value = "grey50",
type = getOption("ggplot2.discrete.fill")
)
... |
Additional parameters passed on to the scale type, |
palette |
One of the following:
|
aesthetics |
The names of the aesthetics that this scale works with. |
na.value |
If |
type |
One of the following:
|
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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.