Some love for ggplot2

With all the recent buzz about ggvis (this, this, and this) it’s often easy to forget all that ggplot2 offers as a graphics package. True, ggplot is a static approach to graphing unlike ggvis but it has fundamentally changed the way we think about plots in R. I recently spent some time thinking about some of the more useful features of ggplot2 to answer the question ‘what is offered by ggplot2 that one can’t do with the base graphics functions?’ First-time users of ggplot2 are often confused by the syntax, yet it is precisely this syntax built on the philosophy of the grammar of graphics that makes ggplot2 so powerful. Adding content layers to mapped objects are central to this idea, which allows linking of map aesthetics through a logical framework. Additionally, several packages have been developed around this philosophy to extend the functionality of ggplot2 in alternative applications (e.g., ggmap, GGally, ggthemes).

I recently gave a presentation to describe some of my favorite features of ggplot2 and other packages building on its core concepts. I describe the use of facets for multi-panel plots, default and custom themes, ggmap for spatial mapping with ggplot2, and GGally for generalized pairs plots. Although this is certainly a subjective and incomplete list, my workflows have become much more efficient (and enjoyable) by using these tools. Below is a link to the presentation. Note that this will not load using internet explorer and you may have to reload if using Chrome to get the complete slide deck. This is my first time hosting a Slidify presentation on RPubs, so please bear with me. The presentation materials are also available at Github.

ggplot2 redux.

What are some of your favorite features of ggplot2??



6 thoughts on “Some love for ggplot2

  1. ggplot is great. lattice is also. lattice also alows layering but not as directly as ggplot. an advantage of lattice is that the syntax is similar describing a fit for a model.

  2. facet_grid() adds a second dimension to facet_wrap() so that the grid of plots can be indexed row-wise by one category and column-wise by another. It is quicker to locate the plot of interest this way, compared with searching every plot header for a particular pair of categories, as with facet_wrap(). It is also more likely to reveal patterns across ordinal categories. Facet_wrap() is preferable when facetting by a single category, to allow the line of plots to “wrap” to a new line.

    • Thanks for the succinct summary, I allude to some of the difference in my presentation but not quite as clear as you’ve described. Personally, I haven’t found much use for facet_wrap aside from the ability to have separate scales for each facet.

  3. Thanks for sharing this material. I like base graphics a lot, even if it has its quirks. I plan on learning ggplot2 thoroughly, but up to now, when things are easy, base was always good enough and when thinks get complicated, I was not firm enough in ggplot2 and so decided to go with base. Ok, that is just me and I will learn ggplot2 in the future.
    However, in most circumstances, both systems work well. Often, you want to use some package and it comes with visualisations included and these are very often base based. And you don’t want to mix base and ggplot2 graphics for their different looks.
    I like the idea realized in the small BlandAltmanLeh package ( ): It offeres both: base and ggplot2 plots. Personally I think it would be neat, if more packages offered the choice.

    • Technically, anything that can be done with ggplot2 can be done with base graphics since ggplot2 is built off of the grid package that comes with base! Base is nice because it provides the building blocks of simple graphs, i.e., high level of customization is possible should you need to do so. ggplot2 is nice because of its use of variable mappings, not to mention the relative ease of producing publication quality figures. It’s a matter of preference. Thanks for reading!

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s