Skip to content
Prev 658 / 885 Next

Choice of graphics package

Randall,

If I understand your concern correctly, in ggplot2 you can create a list that allows you add any set of theme (and other) plot elements by creating a list once and adding that list object to each plot. For example:

my_theme = list(theme_minimal(), 
                           scale_colour_manual(values = c(?blue?, ?red?, ?gray50?)),
                           labs(x=?x-label?, y=?y-label?, colour=?legend title?),
                           theme(axis.text=element_text(colour=?black?, size=15))

ggplot(df, aes(x,y)) +
   geom_point() +
   my_theme

Whatever plot elements you want to use over and over again, just include them in my_theme and then you can add them all at once to any plot. You do still have to add the ?my_theme? line, but it?s just one line, rather than a line for every individual plot element. I have a few groups of elements that I often use together, so I?ve packaged them into a few different lists that I can add to plots as needed. There might also be ways to change the default theme so that you don?t even need the extra line, so maybe Hadley or Ista can discuss that if such an option is available. 

Joel