Get startedGet started for free

Facet plotting spaces

1. Facet plotting spaces

The major advantage of facets is that every plot is drawn on the same plotting space. This makes them all directly comparable.

2. Facets and variable plotting spaces

Nonetheless, you may encounter situations in which you actually don't want this. For example in continuous variables, if the faceted subsets have wildly different ranges you'll just be adding a lot of white space. In the case of categorical data, it's common that each subset may have different groups, so it may not be necessary, or even appropriate to list all groups in each of the faceted plots.

3. Adjusting the plotting space...

Let's look at this with the plot we ended the last video with. We used facet_grid to create rows according to eating habit and columns according to conservation status. To adjust the plotting space, we can use the scales argument.

4. ... but not with fixed scales

If we set this argument to "free_x" we'll allow each column of plot to have their own x axis. However, here we run into a typical problem. We can't use a fixed coordinate space and have free axes as the same time.

5. Adjusting the plotting space

Once we remove the fixed coordinate space, then we can adjust the x axis for each column.

6. Adjusting the plotting space

We can do the same for the y axis by setting the scales argument to "free_y" instead.

7. Adjusting the plotting space

We can adjust both the x and y axes by setting the scales argument to "free". Note that each column and row has at least a common x and y axis respectively.

8. Adjusting the plotting space

Let's take a look at how this works with categorical variables. Each animal has only one eating behavior, stored in the vore variable. If we plotted the bodyweight of each animal in the name variable and facet according to `vore`, we would repeat the full name list in each sub-plot. This occurs when a categorical variable has many levels, like the name, that are not all present in each sub-group of another variable, like vore.

9. Adjusting the plotting space

If we set the scales to free_y, we'll have only those names present in each facet, but the size of each plot is the still the same.

10. Adjusting the plotting space

This behavior can be changed with the spaces argument , which works in the same way as scales: "free_x" allows different sized facets on the x-axis, "free_y" allows different sized facets on the y-axis, and "free" allows different sizes in both directions. Here, we need to use "free_y". This plot already looks great! But there is one more thing we may want to change.

11. Final adjustments

We can rearrange the data frame according to the weight and then redefine the factor levels according to the order in which they appear. This will arrange them in the same way in the plot. Thinking about the order of the names in this case makes the plot more intuitive.

12. Let's practice!

Great, let's head over to the exercises and see this all in action.

Create Your Free Account

or

By continuing, you accept our Terms of Use, our Privacy Policy and that your data is stored in the USA.