ggplot2 themes examples

August 19, 2016
By

(This article was first published on DataScience+, and kindly contributed to R-bloggers)

This short post is exactly what it seems: a showcase of all ggplot2 themes available within the ggplot2 package. I was doing such a list for myself (you know that feeling …”how would it look like with this theme? let’s try this one…”) and at the end I thought it could have be useful for my readers. At least this post will save you the time of trying all different themes just to have a sense of how they look like.
Enjoy!

theme_bw()

theme_bw

theme_classic()

theme_classic

theme_dark()

theme_dark

theme_get()

theme_get

theme_gray()

theme_gray

theme_grey()

theme_grey

theme_light()

theme_light

theme_linedraw()

theme_linedraw

theme_minimal()

theme_minimal

Bonus Track: The Code

Since copy and pasting and right-clicking 9 times to produce all the plots was definitely not acceptable, I wrote a small function to dynamically create and save a png file with different name and content.

library(dplyr) #data manipulation
library(ggplot2) #data visualization

create_file <- function(name){
  path % file.path() %>% png(,width=960,height=480)
}

#this is the template: change the theme (and the name argument) to produce the other plots
create_file(name = "theme_bw")
ggplot(data=diamonds, aes(carat,price ))+
  geom_point(aes(colour= color))+
  theme_bw()
dev.off()

Final notes

Inner ggplot2 structure allows for a nearly infinite number of customizations and extensions.You can have a sense of what I am talking about looking at ggplot2 extensions website or to the ggthemes package vignette by the package author Jeffrey B. Arnold.

    Related Post

    1. Map the Life Expectancy in United States with data from Wikipedia
    2. What can we learn from the statistics of the EURO 2016 – Application of factor analysis
    3. Visualizing obesity across United States by using data from Wikipedia
    4. Plotting App for ggplot2 – Part 2
    5. Mastering R plot – Part 3: Outer margins

    To leave a comment for the author, please follow the link and comment on their blog: DataScience+.

    R-bloggers.com offers daily e-mail updates about R news and tutorials on topics such as: Data science, Big Data, R jobs, visualization (ggplot2, Boxplots, maps, animation), programming (RStudio, Sweave, LaTeX, SQL, Eclipse, git, hadoop, Web Scraping) statistics (regression, PCA, time series, trading) and more...



    If you got this far, why not subscribe for updates from the site? Choose your flavor: e-mail, twitter, RSS, or facebook...

    Comments are closed.

    Search R-bloggers


    Sponsors

    Never miss an update!
    Subscribe to R-bloggers to receive
    e-mails with the latest R posts.
    (You will not see this message again.)

    Click here to close (This popup will not appear again)