theme_bar_dft: Applies a standardised DfT theme to a ggplot bar plot

View source: R/themeXDft.R

theme_bar_dftR Documentation

Applies a standardised DfT theme to a ggplot bar plot

Description

Applies a standardised DfT theme to a ggplot bar plot.

Usage

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,
  ...
)

Arguments

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

Details

This theme has been designed using charting best practice principles.

Examples

## 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)

department-for-transport/dftplotr documentation built on April 3, 2024, 3:55 p.m.