oe_palette | R Documentation |
Color palettes based on the OE style guide
oe_palette(name, n, type = c("discrete", "continuous"))
name |
Name of desired palette. Choices are:
|
n |
Number of colors desired. |
type |
Either "continuous" or "discrete". Use continuous if you want to automatically interpolate between colours. |
A vector of colours.
# If you need more colours than normally found in a palette, you # can use a continuous palette to interpolate between existing # colours pal <- oe_palette("secondary", 21, type = "continuous") image(volcano, col = pal) # We can't directly feed the palette into scale_fill_manual because # the colors are named in the vector. If one provides scale_fill_manual # a named vector, then ggplot2 is trying to match the colors to the # values in the dataframe # One approach: Just directly assign from the palette ggplot(iris, aes(Sepal.Width, Sepal.Length, color = Species)) + geom_point(size = 4) + scale_colour_manual(values = c( "setosa"=oe_palettes$primary[["prime_blue"]], "virginica"=oe_palettes$primary[["prime_grey"]], "versicolor"=oe_palettes$primary[["prime_ltgrey"]])) # Another approach: Create vector of colors by selecting palette, extract # specific colors, and unname cols <- oe_palette("primary")[c("prime_blue", "prime_ltgrey")] %>% unname() ggplot(mtcars, aes(factor(cyl), fill=factor(vs))) + geom_bar() + scale_fill_manual(values = cols) # Another approach: Create vector of colors by seleting palette and unname # it cols <- unname(oe_palette("primary")) ggplot(mtcars, aes(factor(cyl), fill=factor(vs))) + geom_bar() + scale_fill_manual(values = cols) # Another approach: Create vector of colors and then set names (e.g. # to match dataframe values) cols <- oe_palette("primary")[c("prime_blue", "prime_ltgrey")] %>% setNames(c("1", "0")) ggplot(mtcars, aes(factor(cyl), fill=factor(vs))) + geom_bar() + scale_fill_manual(values = cols)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.