• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

Data Viz with Python and R

Learn to Make Plots in Python and R

  • Home
  • Python Viz
  • Seaborn
  • Altair
  • R Viz
  • ggplot2
  • About
    • Privacy Policy
  • Show Search
Hide Search

How to Change ggplot theme with ggthemes

datavizpyr · September 12, 2023 ·

In this post, we will learn how to make beautiful plots with ggplot2 using themes from ggthemes R package. By default ggplot2 makes plots with grey background, using theme_grey(). ggplot2 comes with about 8 complete themes that help us change the look of a given plot. If you want to customize your plot with more options, ggplot2 extension package ggthemes can help help you.

Here we will see three example themes from ggthemes package using palmer penguin dataset.

library(tidyverse)
library(palmerpenguins)
packageVersion("dplyr")
[1] '1.1.2'
packageVersion("ggplot2")
[1] '3.4.3'
penguins %>% head()

# A tibble: 6 × 8
  species island    bill_length_mm bill_depth_mm flipper_length_mm body_mass_g
  <fct>   <fct>              <dbl>         <dbl>             <int>       <int>
1 Adelie  Torgersen           39.1          18.7               181        3750
2 Adelie  Torgersen           39.5          17.4               186        3800
3 Adelie  Torgersen           40.3          18                 195        3250
4 Adelie  Torgersen           NA            NA                  NA          NA
5 Adelie  Torgersen           36.7          19.3               193        3450
6 Adelie  Torgersen           39.3          20.6               190        3650
# ℹ 2 more variables: sex <fct>, year <int>

Let us make a scatterplot between two numerical variables from penguin dataset.

penguins %>% 
  ggplot(aes(body_mass_g, flipper_length_mm, color=island))+
  geom_point()
ggsave("default_ggplot2_theme.png")

By default, ggplot2 uses a theme with grey background.

ggplot2's default theme with grey background
ggplot2’s default theme with grey background

ggthemes offer a number of themes that to change the appearance of a plot made with ggplot. We can add the ggthemes’ theme as additional layer to the plot.

In the example below we make the scatterplot using solarized theme using theme_solarized() by adding as a layer.

penguins %>% 
  ggplot(aes(body_mass_g, flipper_length_mm, color=island))+
  geom_point()+
  theme_solarized()+
  ggtitle("theme_solarized()")
ggsave("ggplot2_theme_solarized_ggthemes.png")
ggthemes' theme_solarized()
ggthemes’ theme_solarized()

In the second example, we change the default ggplot2 theme to a theme that resembles google docs using theme_gdocs().

penguins %>% 
  ggplot(aes(body_mass_g, flipper_length_mm, color=island))+
  geom_point()+
  theme_gdocs()+
  ggtitle("theme_gdocs()")
ggsave("ggplot2_theme_googledoc_ggthemes.png")

ggthemes' google doc theme
ggthemes’ theme_gdocs()

In the third example, we using ggthemes’ theme_wsj() to make the scatter plot with the style that wall street journal uses in their articles.

penguins %>% 
  ggplot(aes(body_mass_g, flipper_length_mm, color=island))+
  geom_point()+
  theme_wsj()+
  ggtitle("theme_wsj()")
ggsave("ggplot2_theme_wallstreet_journal_ggthemes.png")
ggthemes' WSJ theme
ggthemes’ theme_wsj()

Related posts:

Customizing Mean mark to boxplot with ggplot2How To Show Mean Value in Boxplots with ggplot2? Scatterplot with marginal multi-histogram with ggExtraHow To Make Scatterplot with Marginal Histograms in R? ggforce geom_circle(): Annotate with a circleHow To Annotate a Plot with Circle in R Default ThumbnailHow to Make Axis Text Bold in ggplot2

Filed Under: ggplot2 Tagged With: change themes with ggthemes

Primary Sidebar

Tags

Altair barplot Boxplot boxplot python boxplot with jiitered text labels Bubble Plot Color Palette Countplot Density Plot Facet Plot gganimate ggplot2 ggplot2 Boxplot ggplot2 error ggplot boxplot ggridges ggtext element_markdown() Grouped Barplot R heatmap heatmaps Histogram Histograms Horizontal boxplot Python lollipop plot Maps Matplotlib Pandas patchwork pheatmap Pyhon Python R RColorBrewer reorder boxplot ggplot Ridgeline plot Scatter Plot Scatter Plot Altair Seaborn Seaborn Boxplot Stock Price Over Time Stripplot UpSetR Violinplot Violin Plot World Map ggplot2

Buy Me a Coffee

Copyright © 2025 · Daily Dish Pro on Genesis Framework · WordPress · Log in

Go to mobile version