Splitting Plots with Facets in ggplots
Faceting refers to splitting the data into multiple subsets and then displaying plots for the specific subsets in a panel. Such plots are also called small-multiple plots. The facet approach partitions a plot into a matrix of panels. Each panel shows a different subset of the data.
In our scatter plot we grouped the data into bad and good loans using colors. We can use the faceting concept to split the entire graph into two separate panels one for each, good and bad loans. To do so we will use the facet_grid(. ~ ___)
layer. facet_grid
forms a matrix of panels defined by row and column faceting variables. facet_grid(x ~ y)
will display x*y plots even if some plots are empty.
Unlock Premium Content
Upgrade your account to access the full article, downloads, and exercises.
You'll get access to:
- Access complete tutorials and examples
- Download source code and resources
- Follow along with practical exercises
- Get in-depth explanations