Skip to content

Repository files navigation

ggthemes Animated ggthemes hex stickers, cycling through stickers drawn in the package's themes

R-CMD-check Code Coverage Status CRAN downloads CRAN status lifecycle

ggthemes adds themes, scales and geoms to ggplot2 that reproduce the look of well-known publications and software, and of the graphics advocated by Edward Tufte and Stephen Few:

  • Themes after The Economist, The Wall Street Journal, FiveThirtyEight, Excel, LibreOffice Calc, Google Docs, Highcharts, Apple Numbers, Stata, Solarized, base R graphics and more.
  • Color, shape and linetype scales and palettes to match, including colorblind-safe and Tableau palettes. See the palette gallery.
  • Geoms for Tufte’s range frames and minimal box plots, and tools for banking to 45° to choose a plot’s aspect ratio.

The same scatter plot of fuel economy against car weight drawn four ways: with theme_economist(), theme_fivethirtyeight(), theme_wsj() and theme_solarized(), each with its matching color scale.

Installation

Install the released version from CRAN:

install.packages("ggthemes")

Or the development version from GitHub:

# install.packages("pak")
pak::pak("jrnold/ggthemes")

Themes

Every theme is shown below with its matching color scale, where it has one. Each figure links to the theme’s reference page.

Data and base plots used in the examples

library("ggplot2")
library("ggthemes")

mtcars2 <- within(mtcars, {
  vs <- factor(vs, labels = c("V-shaped", "Straight"))
  am <- factor(am, labels = c("Automatic", "Manual"))
  cyl  <- factor(cyl)
  gear <- factor(gear)
})

p1 <- ggplot(mtcars2) +
  geom_point(aes(x = wt, y = mpg, colour = gear)) +
  labs(
    title = "Fuel economy falls with weight",
    x = "Weight (1000 lbs)",
    y = "Fuel economy (mpg)",
    colour = "Gears"
  )

# `theme_map()` intentionally removes axes, so use geographic data rather than
# a scatterplot. `theme_solid()` is likewise intended to leave only geoms.
us_states <- map_data("state")
p_map <- ggplot(us_states, aes(long, lat, group = group)) +
  geom_polygon(aes(fill = region), colour = "white", linewidth = 0.15) +
  coord_map("albers", lat0 = 39, lat1 = 45) +
  guides(fill = "none")

p_solid <- ggplot(mtcars2) +
  geom_point(aes(x = wt, y = mpg, colour = gear), size = 3) +
  guides(colour = "none")

Example plot drawn with theme_base()

p1 + theme_base() +
  scale_colour_colourblind()

Example plot drawn with theme_calc()

p1 + theme_calc() +
  scale_colour_calc()

Example plot drawn with theme_clean()

p1 + theme_clean() +
  scale_colour_tableau()

Example plot drawn with theme_economist()

p1 + theme_economist() +
  scale_colour_economist()

Example plot drawn with theme_excel()

p1 + theme_excel() +
  scale_colour_excel()

Example plot drawn with theme_excel_new()

p1 + theme_excel_new() +
  scale_colour_excel_new()

Example plot drawn with theme_few()

p1 + theme_few() +
  scale_colour_few()

Example plot drawn with theme_fivethirtyeight()

p1 + theme_fivethirtyeight() +
  scale_colour_fivethirtyeight()

Example plot drawn with theme_foundation()

p1 + theme_foundation() +
  scale_colour_colourblind()

Example plot drawn with theme_gdocs()

p1 + theme_gdocs() +
  scale_colour_gdocs()

Example plot drawn with theme_hc()

p1 + theme_hc() +
  scale_colour_hc()

Example plot drawn with theme_igray()

p1 + theme_igray()

Example plot drawn with theme_map()

p_map +
  theme_map()

Example plot drawn with theme_numbers()

p1 + theme_numbers() +
  scale_colour_numbers()

Example plot drawn with theme_pander()

p1 + theme_pander() +
  scale_colour_pander()

Example plot drawn with theme_par()

p1 + theme_par() +
  scale_colour_colourblind()

Example plot drawn with theme_solarized()

p1 + theme_solarized() +
  scale_colour_solarized()

Example plot drawn with theme_solarized_2()

p1 + theme_solarized_2() +
  scale_colour_solarized()

Example plot drawn with theme_solid()

p_solid +
  theme_solid(fill = "#202124") +
  scale_colour_tableau()

Example plot drawn with theme_stata()

p1 + theme_stata() +
  scale_colour_stata()

Example plot drawn with theme_tufte()

p1 + theme_tufte() +
  scale_colour_few()

Example plot drawn with theme_wsj()

p1 + theme_wsj(base_size = 8) +
  scale_colour_wsj()

Color palettes

A sample of the color palettes is shown below. The palette gallery shows every palette in the package.

Swatches of eight palettes: colorblind, Economist, FiveThirtyEight, Few, Solarized, Stata, Tableau 10 and Wall Street Journal.

Geoms

geom_rangeframe() draws Tufte’s range frame, axis lines that span only the range of the data. geom_tufteboxplot() draws his minimal box plot.

ggplot(mtcars, aes(wt, mpg)) +
  geom_point() +
  geom_rangeframe() +
  coord_cartesian(clip = "off") +
  labs(x = "Weight (1000 lbs)", y = "Miles per gallon") +
  theme_tufte()

ggplot(mtcars, aes(factor(cyl), mpg)) +
  geom_tufteboxplot() +
  labs(x = "Cylinders", y = "Miles per gallon") +
  theme_tufte()

Scatter plot of fuel economy against weight with theme_tufte(), whose axis lines span only the range of the data.Tufte-style box plots of fuel economy by number of cylinders: a point for the median and lines for the whiskers.

Learn more

About

Additional themes, scales, and geoms for ggplot2

Topics

Resources

Contributing

Stars

1.4k stars

Watchers

57 watching

Forks

Releases

Packages

Used by

Contributors

Languages