ggplot2 themes examples

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_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. thank to Marcin Kosiński for the contribution (see comments)

library(dplyr)
library(ggplot2)

create_file_and_plot = function(name){
  path = paste(getwd(),"/",name,".png",sep = '') %>% 
         file.path() %>% 
         png(,width=960,height=480)
         eval(parse(text=paste0("print(ggplot(data=diamonds, aes(carat,price ))+ geom_point(aes(colour=  color))+", name,"())")))
  dev.off()
}

sapply(c("theme_bw", "theme_dark"), create_file_and_plot)

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.

10 Comments

  1. MK
    Marcin Kosiński August 25, 2016

    Do you use jekyll or wordpress for your blog?

    Reply
    1. AC
      Andrea Cirillo August 25, 2016

      wordpress at the moment (independent theme), but I am working on the migration to an rmarkdown based site to streamline workflow from analyses to posting.

      Reply
  2. MK
    Marcin Kosiński August 23, 2016

    I also think that this operation might be done in one function call – so that you don’t have to change the `template` every time

    “`
    library(ggplot2)
    library(dplyr)

    create_file_and_plot = function(name){
    paste(getwd(),”/”,name,”.png”,sep = ”) %>%
    file.path() %>%
    png(,width=960,height=480)
    eval(parse(text=paste0(“print(ggplot(data=diamonds, aes(carat,price ))+ geom_point(aes(colour= color))+”, name,”())”)))
    dev.off()
    }

    sapply(c(“theme_bw”, “theme_dark”), create_file_and_plot)
    “`

    Reply
    1. AC
      Andrea Cirillo August 25, 2016

      that’s why I love r folks! Just updated the post aligning it with your proposal. thank you.

      Reply
      1. MK
        Marcin Kosiński August 25, 2016

        I wonder if this update also appears on R-bloggers : ) ?

        Reply
        1. AC
          Andrea Cirillo August 25, 2016

          based on previous experience I think no.

          Reply
  3. MK
    Marcin Kosiński August 23, 2016

    Shouldnt there be ‘name’ instead of ‘path’ in ‘create_file’?

    Reply
    1. AC
      Andrea Cirillo August 23, 2016

      actually not, wordpress was messing things up, now should be fixed. Unfortunately, I had to subtsitute our beloved ‘<-' with that a sad '=' to make it display things properly.
      Thank you for pointing this out!

      Reply
  4. K
    kent37 August 20, 2016

    theme_get() is not a theme, it returns the current theme settings… you might like to try example(theme_bw) for another way to see all the standard themes.

    Reply
    1. AC
      Andrea Cirillo August 20, 2016

      thank you kent for your useful comment, just updated the post. About example() it is actually a nice feature, what I was trying to produce here was a quick visual reference. thank you again.

      Reply

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.