-
Notifications
You must be signed in to change notification settings - Fork 0
/
dogs.Rmd
55 lines (41 loc) · 1.26 KB
/
dogs.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
---
title: Analyze AOD vs. weight in dog breeds
author: Peter Carbonetto
output: workflowr::wflow_html
---
*Add introductory text here.*
```{r knitr-opts, include=FALSE}
knitr::opts_chunk$set(comment = "#",collapse = TRUE,results = "hold",
fig.align = "center")
```
*Add text here.*
```{r load-pkgs, message=FALSE, warning=FALSE}
library(ggplot2)
library(cowplot)
```
Import data
-----------
Read the height, weight and age-of-death (AOD) data for different
dog breeds. These data accompany [Jones *et al*, 2008][jones-2008].
```{r read-data}
dogs <- read.csv("../data/dogs.csv",stringsAsFactors = FALSE)
```
Find "best-fit" line
--------------------
Find the line that best predicts AOD given body weight (in pounds).
```{r fit-lm}
fit <- lm(AOD ~ weight,dogs)
b <- coef(fit)
```
Plot AOD vs. body weight
------------------------
Plot age-of-death vs. body weight, along with the best-fit line (the
dashed, blue line). Compare with Figure 4 from Jones *et al* (2008).
```{r}
ggplot(dogs,aes(x = weight,y = AOD)) +
geom_point(color = "black") +
geom_abline(intercept = b["(Intercept)"],slope = b["weight"],
color = "darkorange",linetype = "dashed") +
theme_cowplot()
```
[jones-2008]: https://doi.org/10.1534/genetics.108.087866