Custom ggplot2 themes

Communicating with Data in the Tidyverse

Timo Grossenbacher

Data Journalist

The advantages of a custom look

Communicating with Data in the Tidyverse

The theme() function

ggplot(plot_data) +
  geom_histogram(aes(
    x = working_hours)) +
  labs(x = "Working hours per week",
       y = "Number of countries") +
  theme(
    text = element_text(
      family = "Bookman",
      color = "gray25")
  )

Communicating with Data in the Tidyverse

Default ggplot2 themes

ggplot(plot_data) +
  geom_histogram(aes(
    x = working_hours)) +
  labs(x = "Working hours per week",
       y = "Number of countries") +

  theme_classic()

Communicating with Data in the Tidyverse

Chaining theme() calls

ggplot(plot_data) +
  geom_histogram(aes(
    x = working_hours)) +
  labs(x = "Working hours per week",
       y = "Number of countries") +

  theme_classic() +
  theme(
    text = element_text(
      family = "Bookman",
      color = "gray25")
  )

Communicating with Data in the Tidyverse

Theme configuration options

?theme

axis.title
label of axes (element_text; inherits from text)

axis.title.x
x axis label (element_text; inherits from axis.title)

axis.title.x.top
x axis label on top axis (element_text; inherits from axis.title.x)

axis.title.x.bottom
x axis label on bottom axis (element_text; inherits from axis.title.x)

Communicating with Data in the Tidyverse

The element_* function family

element_text()
element_rect()
element_line()
element_blank()
ggplot(plot_data) +
  geom_histogram(aes(
    x = working_hours)) +
  labs(x = "Working hours per week",
       y = "Number of countries") +
  theme(
    text = element_blank()
  )

Communicating with Data in the Tidyverse

Let's try out themes!

Communicating with Data in the Tidyverse

Preparing Video For Download...