theme_bar_dft | R Documentation |
Applies a standardised DfT theme to a ggplot bar plot.
theme_bar_dft(
legend_position = "bottom",
base_family = "",
base_size = 14,
base_line_size = 2,
margin_sizes = c(2, 1, 1, 1),
accuracy = 1,
flip = FALSE,
palette = "main.palette",
gradient = FALSE,
...
)
legend_position |
the desired legend position. Selects bottom by default. |
base_family |
Font family |
base_size |
The base font size |
base_line_size |
The base line size |
margin_sizes |
The margin size in cm. Takes a list of the four margins in the order top, right, bottom, left. |
accuracy |
The accuracy of the y-axis, default to 1 for 0 decimal place. 0.1 would give 1 decimal place, 0.01 would give 2 decimal places. |
flip |
Boolean response whether to flip the x and y-axis. Defaults to false. |
palette |
The name of the DfT palette you want to use |
gradient |
Boolean response whether to use gradient palette instead of standard palettes. Defaults to false. |
... |
Other arguments to pass to extract gradients function |
This theme has been designed using charting best practice principles.
## Simple bar chart with a flipped axis and legend at the top
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_bar_dft(flip = TRUE, legend_position = "top")
## More complex bar chart with another dft palette selected.
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_bar_dft(flip = TRUE, legend_position = "top", palette = "just.beachy")
## More complex bar chart with another dft palette selected and gradient used.
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_bar_dft(flip = TRUE, legend_position = "top", palette = "just.beachy", gradient = TRUE)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.