Posted by Rafael Martinez-Feria
Grammar of grahics* (GoG) is the theory behing Hardly Wickam’s ggplot2 package. In his 2010 paper, Leland Wilkinson describes GoG as a system to produce a statistical graphics. The system contains seven GoG classes embedded in a data flow, which represent the sequence of mappings needed to a graphic from a set or multiple sets of data. The figure below (taken form Wilkinson’s paper) shows the data flow of the classes.
2 and 3. Algebra and Scales are transformations on varsets. For instance, below we trasnform the scale of the x axis using scale_x_sqrt()
stat_bin2d()
function performs a summary of counting points within a 2d-bin statistic.aes()
function to tell ggplot what VARSET we want it to use to map the graph. In this example, we add a regresion line to a set of groups.Becasue of its workflow (you have to run through GoG workflow every time) ggplot2 tends to be slower than other base graphic system.
It may sometimes be difficult to determine whether what you want to see in the graphic is an aesthetic, or a fixed values (takes a couple of tries to wrap your head around it).
Although tidy data works beautifully with ggplot2 (and the GoG paradigm), that means that you may need to invest sometime/code tiding your data. It is be harder to pass on to ggplot2 an aes()
if data is not tidy. You may end up having multiple geom layers.