When you learn grammar in school you learn about the basic units to construct a sentence. The basic units in the “grammar of graphics” consist of:
- The data or the actual information you wish to visualize.
- The geometries, shortened to “geoms”, describe the shapes that represent our data. Whether it be dots on a scatter plot, bar charts on the graph, or a line to plot the data! The list goes on. Geoms are the shapes that “map” our data.
- The aesthetics, or the visual attributes of the plot, including the scales on the axes, the color, the fill, and other attributes concerning appearance.
Another key component to understand is that in ggplot2, geoms are “added” as layers to the original canvas which is just an empty plot with data associated to it.
Once you learn these three basic grammatical units, you can create the equivalent of a basic sentence, or a basic plot. There are more units in the “grammar of graphics,” but in this lesson we’ll mostly be learning about these three.
Take a look at the code that generates the plot on the graph, you will understand every single line of what it’s doing by the end of this lesson! For now, focus on the plus signs! Each plus sign is adding a layer to the plot!