Chapter 5 – Advanced Plotting

Building on what we learned in the previous chapters, we are going to take it to the next level in this chapter, by creating more complex plots, either by integrating more statistical elements, or by plotting more variables into the same plot space by leveraging additional functions.

If you are in Sociology 1205, this chapter covers the EDA module for unit 5. You will find the tutorial scripts in your R Studio Cloud workspace.

The more complex plotting we are going to do here should really be done after the simpler plotting we have done in the previous chapters. The goal of adding more variables or statistics to our plots is to refine patterns and insights we may have identified using simpler plots. The more complex plots require more attention to extract more granular information from them.

Learning Objectives

In this chapter, we’ll cover the following topics:

  • how to plot three or more variables;
  • how to add statistics to a plot.

Tutorial 1 – Plotting Statistics

Tutorial 2 – Part 1

Tutorial 2 – Part 2

Tutorial 3

Key functions used in this chapter

  • geom_smooth(): the function that adds a smoother to a plot;
  • geom_quantile(): the function that adds a quantile line to a plot;
  • quantiles(): the function that calculates specified quantiles from a dataset;
  • subset(): the function that takes a subset of a dataset;
  • facet_grid(): the function that creates a grid to plot multiple variables.

Before moving on to the next chapter, or to the exercise if you are in Sociology 1205, test your understanding with the quiz below.

License

Icon for the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License

Visualizing Data with R Copyright © 2022 by Christine Monnier is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License, except where otherwise noted.

Share This Book