ggplot2 is awesome. It enables people to easily make high quality data visualization plots. However, people who spent a lot of time with ggplot2 have love/hate relationship with the default ggplot2 theme, where a plot is on a grey background. The default ggplot2 theme is called theme_grey() or theme_gray(). In addition to the default theme, ggplot2 to has 7 other themes that can elevate your graphics. Here we will look at all 8 themes that are readily available with ggplot. One of my favorites is theme_bw() or theme_classic(). Learn these 8 ggplot2 themes and find out which is your favorite.
Let us use gapminder data to make a scatter plot and save the ggplot object. We will use the ggplot object in our examples with the themes for ggplot.
head(gapminder) p_obj <- gapminder %>% sample_n(200) %>% ggplot(aes(x=lifeExp, y=gdpPercap)) + geom_point(alpha=0.5)+ scale_y_log10() p_obj
1. theme_gray()
The default theme of ggplot is grey. We can also specify grey theme with grey_theme() and add it as a layer.
grey <- p_obj +theme_gray() +labs(subtitle = "theme_gray()") grey
2. theme_bw()
bw <- p_obj +theme_bw()+labs(subtitle = "theme_bw()") bw
3. theme_classic()
classic <- p_obj + theme_classic() +labs(subtitle = "theme_classic()") classic
4. theme_dark()
dark <- p_obj + theme_dark() +labs(subtitle = "theme_dark()") dark
5. theme_light()
light <- p_obj + theme_light() + labs(subtitle = "theme_light()") light
6. theme_linedraw()
linedraw <- p_obj + theme_linedraw() +labs(subtitle = "theme_linedraw()") linedraw
7. theme_minimal()
minimal <- p_obj + theme_minimal() +labs(subtitle = "theme_minimal()") minimal
8. theme_void()
void <- p_obj + theme_void()+labs(subtitle = "theme_void()") void
library(gridExtra) grid.arrange( grey, bw, light, dark, classic,linedraw, minimal, void, ncol=2)