Today we will cover several remaining layer types and examples in the grammar of graphics.
For the final time, we’ll make use the gapminder dataset:
A special layer type within the ggplot2 framework, facets allow us to produce many small plots for each value of a character variable. It can be added onto almost any other plot.
Notice that the scales of the axes are all the same. Sometimes this is
useful, but in other cases it is useful to allow these to change. We
can do this by adding the option
There are also options
scales="free_y" if you
would like to only allow one axis to change.
Another layer type are scales. These control the exact way that aesthetics are mapped to visual features. For example, we have seen that we can change the color pallet used with the viridis package:
Similarly, we can add
scale_y_log10() to plot
values on the logarithmic scale:
There are a lot of things you can do with the scale functions by changing the default options:
I won’t quiz you on the details of these, but look back to these notes when you find ourself wanting to do something with the scales or range of the plot.
For today’s class, we will starting working on the next project, Project B.