First we load the mosaic package, and then read in the data from a file.

library(mosaic)
exampleData <- read.file("http://colindawson.net/data/fitted_residual_example.txt")

Now, let’s plot the data with a line

gf_point(y ~ x, data = exampleData) %>% 
  gf_smooth(method = "lm")
## Warning: `data_frame()` was deprecated in tibble 1.1.0.
## Please use `tibble()` instead.

Let’s fit the model and store it as an lm object.

theModel <- lm(y ~ x, data = exampleData)

How do the conditions look? Let’s check the standard residual plots.

gf_point(residuals(theModel) ~ fitted.values(theModel)) %>%
  gf_smooth(method = "lm")

Now a density histogram of the residuals (overlaying a smooth density curve)

gf_dhistogram(~residuals(theModel)) %>%
  gf_density()

What does a QQ plot look like for these residuals?

gf_qq(~residuals(theModel)) %>%
  gf_qqline()