scale_fill_dft | R Documentation |
Function to use custom DfT palettes for fill colours in ggplot charts
scale_fill_dft(palette = "main.palette", gradient = FALSE, ...)
palette |
Named DfT palette to use in the fill. Defaults to "main.palette" |
gradient |
Boolean response whether to use gradient palette instead of standard palettes. Defaults to false. |
... |
Other arguments to pass to extract gradients function |
## Simple bar chart using default palette
library(ggplot2)
df <- mpg[mpg$class %in% c("subcompact", "compact", "midsize", "suv"),]
ggplot(df, aes(manufacturer)) +
geom_bar(aes(fill=class), width = 0.5) +
theme(axis.text.x = element_text(angle=65, vjust=0.6)) +
scale_fill_dft()
## Simple bar chart using alternative palette
library(ggplot2)
df <- mpg[mpg$class %in% c("subcompact", "compact", "midsize", "suv"),]
ggplot(df, aes(manufacturer)) +
geom_bar(aes(fill=class), width = 0.5) +
theme(axis.text.x = element_text(angle=65, vjust=0.6)) +
scale_fill_dft("just.beachy")
## Larger bar chart using longer palette
library(ggplot2)
df <- mpg[mpg$class %in% c("subcompact", "compact", "midsize", "suv", "pickup", "minivan"),]
ggplot(df, aes(manufacturer)) +
geom_bar(aes(fill=class), width = 0.5) +
theme(axis.text.x = element_text(angle=65, vjust=0.6)) +
scale_fill_dft(palette = "clear.skies")
## Larger bar chart using gradient palette
library(ggplot2)
ggplot(mpg, aes(manufacturer)) +
geom_bar(aes(fill=class), width = 0.5) +
theme(axis.text.x = element_text(angle=65, vjust=0.6)) +
scale_fill_dft(gradient = TRUE, n = 7)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.