One of my favorite aspects of ggplot2 is the use of themes. Not including a theme, the default ggplots theme is the theme_grey which has a dark grey background with white grid lines. See the example below
You see these plots all over the web and in presentations now and you can recognize the ggplot2 style.
There are a several “canned” themes that come with ggplot that offer themes do change the way the plot looks without having to edit every aspect of the visual presentation of the plot
theme_bw()
The classic dark-on-light ggplot2 theme. May work better for presentations displayed with a projector.
theme_linedraw()
A theme with only black lines of various widths on white backgrounds, reminiscent of a line drawings. Serves a purpose similar to theme_bw. Note that this theme has some very thin lines (« 1 pt) which some journals may refuse.
theme_light()
A theme similar to theme_linedraw but with light grey lines and axes, to direct more attention towards the data.
theme_minimal()
A minimalistic theme with no background annotations.
theme_classic()
A classic-looking theme, with x and y axis lines and no gridlines.
theme_dark()
The dark cousin of theme_light, with similar line sizes but a dark background. Useful to make thin coloured lines pop out.
theme_void()
A completely empty theme.
The problem with the default theme in ggplot is that these do not work for presentation formats (e.g., publication in a journal or presentation).
Other themes
There are lots of themes available online in various places. There is also the package ggthemes that offers many different themes and scales for graphics. Check out the gallery here.
While the theme_bw() is ok it does not meet publication quality figures (atleast in my field) or my typical presentation format. The great thing about ggplot is the ability to customize and create your own themes.
I have a few that I use on a regular basis The basic process is fairly straight forward. You start with the theme_bw and modify using %+replace% the aspects you wish to change (you do not need to specify all aspects).
theme_mine
theme_mine is the theme I use most often and is what I generally use for pubs.
theme_presentation
My general format in presentations is to have a black background with white, yellow, and green text. I therefore created a theme (theme_presentation)that would work with the required black background and white text.
theme_map
I do a lot of map creation using ggplot and therefore the canned themes and the previous themes I discussed do not really fit. So I created a theme (theme_map).
These files are included in a single file I call themes.r which I load as a source file in the housekeeping section of my R code.
Faceting
Faceting is the process of combining several plots together in a single figure. ggplot has two means of doing this, facet_grid and facet_wrap. I saw in a recent post that the ggplot2 version 2.2 will have a major revamp of facets.
facet_grid()
Lay out panels in a grid.
Messing with a few options in facet_grid
scales and space
facet labels
margins
facet_wrap()
Lay out one dimension ribbon of panels into two dimensions. Many of the options in facet_grid are the same in facet_wrap.
gridExtra
Notice that in the above plot, the two figures do not exactly line up. This takes a little finagling.
Outputting plots
You have two options when you are trying to output a plot.
Check out the options ?ggsave
The other option that I use, particularly when you want to change the background color.