Adding Themes to your ggplots in R

Themes are a convenient way change the appearance of ggplots that you have created in R. In the video and code below I provide examples from a variety packages, showing themes that range from professional and serious, like the Wall Street Journal, BBC, and FiveThirtyEight, through to fun ones styled after TV themes like The Simpsons and Rick and Morty.


Subscribe below to get updates on my latest videos, courses, and other useful information.


library(tidyverse)

testplot<- ggplot(mtcars, aes(x = wt, y = mpg, colour = factor(gear))) +
  geom_point() +
  ggtitle("Cars")
testplot

############ ggthemes ############
library(ggthemes)

testplot + scale_color_fivethirtyeight() + theme_fivethirtyeight()
testplot + scale_color_economist() + theme_economist()
testplot + theme_wsj()

############ bbplot for bbc style ############
devtools::install_github('bbc/bbplot')
library(bbplot)
testplot + bbc_style()

############ ggthemr ############
devtools::install_github('Mikata-Project/ggthemr')
library(ggthemr)
ggthemr("chalk")
testplot
ggthemr_reset()
# Note reset doesn't seem to always switch all defaults back 
# but restarting R will

############ tv themes ############
library(tvthemes)

# download special fonts
import_simpsons()         ## "Akbar" font
import_rickAndMorty()     ## "Get Schwifty" font
import_roboto_condensed() ## "Roboto Condensed" Google Font import from hrbrthemes

# adding fonts to R (seems to vary a lot by OS and system)
library(extrafont)
font_import()
loadfonts(device="win")

data <- gapminder::gapminder %>% 
  filter(country %in% c("France", "Germany", "Ireland", "Italy", "Japan", "Norway", "Belarus")) %>% 
  mutate(year = as.Date(paste(year, "-01-01", sep = "", format='%Y-%b-%d')))
ggplot(data = data, aes(x = year, y = gdpPercap, fill = country)) +
  geom_area(alpha = 0.8) +
  scale_x_date(breaks = data$year, date_labels = "%Y") +
  scale_y_continuous(expand = c(0, 0), labels = scales::dollar) +
  scale_fill_simpsons() +
  labs(title = "The Simpsons",
       caption = glue::glue("A 'Bake 'em Away, Toys!' Production"),
       x = "Wel-diddly-elcome neighborino!",
       y = "Price of Duff Beer") +
  theme_simpsons(title.font = "Akbar",
                 text.font = "Akbar",
                 axis.text.size = 8)
  

ggplot(diamonds, aes(price, fill = cut)) +
  geom_histogram(binwidth = 500) +
  scale_fill_rickAndMorty() +
  labs(title = "Dammit Morty, You Know Diamonds Aren't Forever Right?",
       subtitle = "They're blood diamonds, Morty **burp**",
       caption = "Wubbalubbadubdub!") +
  theme_rickAndMorty(title.font = "Get Schwifty",
                     text.font = "Get Schwifty",
                     title.size = 14)