3Facets
Facets represent one of the typical modalities for data visualization. The idea is to have a grid of plots presented as a unique visualization. Graphics presented as facets, however, are not independent and uncorrelated; on the contrary, they are the graphics produced by selecting a specific data frame variable/column, and for each of its unique values, a plot is produced by using common ggplot definition and aesthetics. For example, we may want to visualize the tourist arrivals in some locations on a yearly basis. So, if we have a time series (i.e., the yearly tourist arrivals) but observed in more than one context (e.g., different countries), how would we represent it graphically? There are alternatives. For example, with a line plot, each line representing data of a certain country, or with a stacked bar plot, with each stacked segment corresponding to a country. But we might also prefer to look at the data of the different countries separately rather than condensed into a single plot, for instance for better clarity; in that case, how do we do that? The trivial solution would be to extract subset of rows from the data frame, one subset for each country, and plot them individually. It works, of course, but it is inefficient, and we end up with several distinct plots to manage somehow. Here comes the facet visualization with a clever solution that allows, in a single execution, creating a grid of plots, one for each country with the yearly tourist arrivals. Cases ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access