Chapter 4

Kicking It Up a Notch to ggplot2

IN THIS CHAPTER

Bullet Graduating to ggplot2

Bullet Wrapping things up

The base R graphics toolset will get you started, but if you want to shine at visualization, it’s a good idea to learn ggplot2. Created by R megastar Hadley Wickham, the gg in the package name stands for “grammar of graphics,” and that’s a good indicator of what’s ahead. That’s also the title of the book (by Leland Wilkinson) that is the source of the concepts for this package.

In general, a grammar is a set of rules for combining things. In the grammar that people are most familiar with, the things happen to be words, phrases, and clauses. The grammar of our language tells you how to combine these components to produce valid sentences.

So, a “grammar of graphics” is a set of rules for combining graphics components to produce graphs. Wilkinson proposed that all graphs have underlying common components — like data, a coordinate system (the x- and y-axes you know so well, for example), statistical transformations (like frequency counts), and objects within the graph (dots, bars, lines, or pie slices, for example — to name just a few).

Just as combining words and phrases produces grammatical sentences, combining graphics components produces graphs. And just as some sentences are grammatical ...

Get Data Analytics & Visualization All-in-One For Dummies now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.