Facet grids
Facet grids create a figure in the form of a matrix of rows and columns to plot multiple graphics side by side. Those graphics are subplots of one or more variables, facilitating the visualization of the relationship of a variable with others separately. In summary, facet grids show small plots representing a subgroup of the data.
We can see what a facet grid looks like using the diamonds dataset, which is built into ggplot2 (type ?diamonds
into R’s console for the documentation). This data has the cuts, dimensions, colors, prices, and other attributes of 54,000 diamonds. If we want to see a scatterplot of the prices by carat, the graphic will look busy, as we can see in Figure 11.1. Notice that it is difficult to see the trends and relationships for each cut type, such as Fair or Good. They will be hidden under other points. What we see is the general trend and relationship for the entire dataset.
Figure 11.1 – Scatterplot of...