Themes to spice up visualizations with ggplot2 | by Abhinav Malasi | Towards Data Science

On a single glance, when you look at a visualization, few things pop out, which may vary from person to person. Those eye-catching features can be the charts or images, colors used, text style, or even the background. If you are into data visualization and familiar with principles for creating good visualization. Then surely, you must have an idea that a chart consists of data and the skeleton. Whatever is left in the visualization is the skeleton that deals with the axis, annotations, and the background, commonly known as the theme.
If you are an R user, then probably you would know by now that the ggplot2 package has limited themes. But the ggplot2 package gives the option to customize your very own theme.
Interested in customizing your theme then check this article:
towardsdatascience.com
If customizing your theme is too time-consuming, then R lovers have created extensions for the ggplot2 package that provide themes compatible with the package.
Here I have compiled a list of packages that provides themes compatible with the ggplot2 package. This is not an exhaustive list but covers most of the packages that provide extensions to the ggplot2 package. The list goes as:
The package provides 15 themes; I listed some of the notable ones below:
theme_economist: based on The Economist magazine’s plots.
theme_few: follow the teachings of Stephen Few’s “Practical Rules for Using Color in Charts”.
theme_fivethirtyeight: to create plots based on the fivethirtyeight.com theme.
theme_tufte: based on the design principles described by Tufte in The Visual Display of Quantitative Information.
theme_wsj: based on The Wall Street Journal’s plots.
Apart from themes, there are geoms based on Tufte’s work and scales. Here is a link for the complete list.
There are 9 themes offered in the hrbrthemes package that is typography-focused and compatible with the ggplot2 package.
theme_ipsum: Arial Narrow
theme_ipsum_gs: Goldman Sans Condensed
theme_ipsum_es: Econ Sans Condensed
theme_ipsum_rc: Roboto Condensed
theme_ipsum_ps: IBM Plex Sans font
theme_ipsum_pub: Public Sans
theme_ipsum_tw: Titilium Web
theme_modern_rc: Roboto Condensed dark theme
theme_ft_rc: Dark theme based on FT’s dark theme (Roboto Condensed)
The package also provides additional scales, color palettes, fonts, R markdown templates, and other utilities.
Here are several ways to install the package.
install.packages("hrbrthemes") # NOTE: CRAN version is 0.8.0# orinstall.packages("hrbrthemes", repos = c("https://cinc.rud.is", "https://cloud.r-project.org/"))# orremotes::install_git("https://git.rud.is/hrbrmstr/hrbrthemes.git")# orremotes::install_git("https://git.sr.ht/~hrbrmstr/hrbrthemes")# orremotes::install_gitlab("hrbrmstr/hrbrthemes")# orremotes::install_bitbucket("hrbrmstr/hrbrthemes")# orremotes::install_github("hrbrmstr/hrbrthemes")
The package by Urban Institute to make plotting easier for the people working there. For a complete guide to working with the urbnthemes package, check out the Urban Institute R Users Group website for a comprehensive list of examples.
To install the package, first, install remotes library and then the urbnthemes package.
install.packages("remotes")remotes::install_github("UrbanInstitute/urbnthemes", build_vignettes = TRUE)
The package created by the BBC News data team provides 2 functions:
bbc_style(): the function with no arguments sets the basic formatting of the plot to that of BBC. The function just needs to be added to the ggplot() function.
finalise_plot(): the function has 6 arguments of which 3 are default and 3 needs to be supplied. The function saves the plot and adjusts titles, subtitles, and other formattings according to the BBC chart creation guidelines.
Here are the graphics created using the bbplot package.
Garrick Aden-Buie's inspiration to create the ggpomological package came from the images from the USDA Pomological Watercolor Collection. The package provides three themes, a color palette based on the watercolors, fonts, and paper texture background.
The three themes are:
theme_pomological(): watercolor styling theme based on paper background.
theme_pomological_plain(): this theme is like the previous theme but with white or transparent background.
theme_pomological_fancy(): colored paper background with fancy handwritten fonts.
The package provides 17 unique built-in color themes to create different styled charts. Here are a few examples of the themes from the ggthemr package.
Interested in creating visuals using the color schemes of your favorite tech company, then check out the ggtech package by Ricardo Bion.
devtools::install_github("ricardo-bion/ggtech",                           dependencies=TRUE)
Airbnb
Etsy
Facebook
Google
Twitter
23andme
If you are not a tech lover but more of a TV buff, then check out the tvthemes package by Ryo Nakagawara that might interest you.
This is how you can install the package:
devtools::install_github("Ryo-N7/tvthemes")
The list of themes are:
Avatar: The Last Airbender
Brooklyn Nine-Nine
Game of Thrones/A Song of Ice & Fire
Rick & Morty
Parks & Recreation
The Simpsons
Spongebob Squarepants
Hilda
Attack on Titan
Kim Possible
Big Hero 6
Gravity Falls
Here are some sample charts created using the tvthemes:
The package created by Dataroots has 12 inbuilt themes and 24 color palettes to choose from. One of the key features that distinguish this package from others is the ease of adding a watermark with a single line of code. We can install the package with the help of the devtools package as shown below.
devtools::install_github('datarootsio/artyfarty')
Firatheme by Erik-Jan van Kesteren is based on Trafford Data lab theme and Fira Sans fonts from Mozilla. The package provides a single theme (theme_fira()) and color palette generated from coolors. We can save plots using the firaSave() function.
The package installation can be done as:
remotes::install_github("vankesteren/firatheme")
This package is the stylized version of webcomics XKCD for ggplot.
Do you enjoy working in dark mode then check this package? ggdark creates a dark mode version of ggplot2 themes. Once you have installed the ggdark package, just turn any ggplot2 default themes into dark mode by adding dark_ before the theme name, such as dark_theme_void() or dark_theme_minimal().
I believe to have covered most of the ggplot2 extensions that can spice up your data visualizations. If I am missing out on your favorite theme or package, let me know, and I will add it to the list. Till then, enjoy creating outstanding charts using the R and ggplot2 package.
If you enjoy reading the articles written by me then you can support me by subscribing to the Medium using the below referral link.
abhinav-malasi.medium.com
To stay up to date, you can subscribe to email notifications whenever I publish my articles.
abhinav-malasi.medium.com
You can connect with me on LinkedIn and Twitter to follow my data science and data visualization journey. Or you can follow me on Medium to stay updated on new articles on data visualization with R and ggplot2 package.