A residual plot is a graph that displays the residuals on the vertical axis specified and the independent variable on the horizontal axis. In the event that the points in a residual plot are dispersed in a random manner around the horizontal axis, it is appropriate to use a linear regression model for the data. If the data is not dispersed, a non-linear model is more appropriate.
We can create and customize the residual plot using the steps mentioned as follows:
- Include the library within the R workspace. This is considered a mandatory step:
> library(ggplot2)
Attaching package: 'ggplot2'
The following object is masked _by_ '.GlobalEnv':
mpg
Warning message:
package 'ggplot2' was built under R version 3.5.3
- Use the required function, such as we did for scatter plots, to get the perpendicular plots arranged in a systematic manner: ...