Creating a layered plot with a scatter plot and fitted line

To visualize a relation between two numeric variables, we usually create a scatter plot. We also add a fitted line or smooth curve to the scatter plot, which represents the majority of the data points. In this recipe, we will see how we can produce a scatter plot and then add a layer of fitted line along with a linear smooth and curved line. The curved line could be the lowess or local regression, but here, is loess the default.

Getting ready

Once again, we recall ggplotdata for this plot. In this case, we will use the two numeric variables, which are disA and disD.

How to do it...

Perform the following steps:

  1. We can easily produce the scatter plot with the ggplot function along with the ...

Get R: Data Analysis and Visualization now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.