```{r, include = FALSE}
library(tidyverse)

## Some customization.  (Leave this part alone)

theme_set(theme_bw()) # change theme for ggplot2

## Sets default "chunk options"
knitr::opts_chunk$set(
  tidy=FALSE,       # display code as typed
  size="small",     # slightly smaller font for code
  message = FALSE)  # suppresses some unwanted output
```


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

```{r, message = FALSE}
library(mosaic)
```


```{r}
exampleData <- read.file("http://colindawson.net/data/fitted_residual_example.txt")
```

Now, let's plot the data with a line

```{r}
gf_point(y ~ x, data = exampleData) %>% 
  gf_smooth(method = "lm")
```

Let's fit the model and store it as an `lm` object.
```{r}
theModel <- lm(y ~ x, data = exampleData)
```

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

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

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

```{r}
gf_dhistogram(~residuals(theModel)) %>%
  gf_density()
```


What does a QQ plot look like for these residuals?

```{r}
gf_qq(~residuals(theModel)) %>%
  gf_qqline()
```