Introduction
In this document, we will explore various themes and styles available in ggplot2.
library(ggplot2)
library(ggthemes)
# Basic plot
p <- ggplot(mpg, aes(x=displ, y=hwy, color=class)) +
geom_point() +
labs(title="Default Theme")
p
Below are examples of applying different basic themes to your plot:
Theme Gray
p + theme_gray() +
labs(title="Theme Gray")
Theme Dark-on-light
p + theme_bw() +
labs(title="Theme BW")
Theme Linedraw
p + theme_linedraw() +
labs(title="Theme Linedraw")
Theme Light
p + theme_light() +
labs(title="Theme Light")
Theme Dark
p + theme_dark() +
labs(title="Theme Dark")
Theme Minimal
p + theme_minimal() +
labs(title="Theme Minimal")
Theme Classic
p + theme_classic() +
labs(title="Theme Classic")
Theme Void
p + theme_void() +
labs(title="Theme Void")
Theme Test
p + theme_test() +
labs(title="Theme Test")
Themes in ggthemes
Below are examples of applying additional themes using package ggthemes to your plot:
Theme Economist
p + theme_economist() +
labs(title="Theme Economist") +
scale_color_economist()
Theme Economist - White
p + theme_economist_white() +
labs(title="Theme Economist - White") +
scale_color_economist()
Theme Excel
p + theme_excel() +
labs(title="Theme Excel") +
scale_color_excel()
Theme Excel - New
p + theme_excel_new() +
labs(title="Theme Excel - New") +
scale_color_excel_new()
Theme LibreOffice Calc
p + theme_calc() +
labs(title="Theme Calc") +
scale_color_calc() +
scale_shape_calc()
Theme Highcharts
p + theme_hc() +
labs(title="Theme Highcharts") +
scale_color_hc()
Theme Google Docs
p + theme_gdocs() +
labs(title="Theme Google Docs") +
scale_color_gdocs()
Theme Clean
p + theme_clean() +
labs(title="Theme Clean") +
scale_color_canva()
Theme 538
p + theme_fivethirtyeight() +
labs(title="Theme 538")
Theme igray
p + theme_igray() +
labs(title="Theme igray")
Theme few
p + theme_few() +
labs(title="Theme few") +
scale_color_few()
Theme Solarized
# light
p + theme_solarized() +
labs(title="Theme Solarized") +
scale_color_solarized()
# light2
p + theme_solarized_2() +
labs(title="Theme Solarized2") +
scale_color_solarized()
# dark
p + theme_solarized(light = FALSE) +
labs(title="Theme Solarized Dark") +
scale_color_solarized()
Theme tufte
p + theme_tufte() +
labs(title="Theme tufte")
Theme Stata
p + theme_stata() +
labs(title="Theme Stata") +
scale_color_stata() +
scale_shape_stata()
Theme Wall Street Journal (WSJ)
p + theme_wsj() +
labs(title="Theme Wall Street Journal")
Theme Pander
p + theme_pander() +
labs(title="Theme Pander") +
scale_color_pander()
Theme Tidyquant
library(tidyquant)
# Tidyquant - basic
p + theme_tq() +
labs(title="Theme Tidyquant") +
scale_color_tq()
# dark
p + theme_tq_dark() +
labs(title="Theme Tidyquant Dark") +
scale_color_tq()
# green
p + theme_tq_green() +
labs(title="Theme Tidyquant Green") +
scale_color_tq()
Custom Theme
custom_theme <- theme(
plot.title = element_text(size = 14, face = "bold", hjust = 0.5),
axis.title = element_text(size = 12, face = "bold"),
axis.text = element_text(size = 10),
panel.background = element_rect(fill = "white"),
panel.grid.major = element_line(color = "grey", linewidth = 0.5),
panel.grid.minor = element_line(color = "lightgrey", linewidth = 0.25)
)
p + custom_theme + labs(title = "Custom Theme")
Back to top