---
author: "<Who am I?>"
title: "Class 2 notes"
date: "`r Sys.Date()`"
format: html
editor: source
---

# Introduction

You are welcome to follow along here to take notes, or take breaks to program when we do. This is a "Quarto" file, which is sort of next-generation RMarkdown. To be honest, *I'm* still working out some of the differences. But the good news is that if you know `.Rmd` you should be fine, and if you don't this is not really noticeably different.

## Milestones of adulthood

Read in the data in `milestone.csv` stored in the folder `data/`.

Use the code chunk below as a start. Code chunks cœœan be lengthy or brief.

```{r}
#| label: read-milestone
dat <- read.delim(file="./data/milestone.csv", header = TRUE, sep = ',')
head(dat, n = 5)
tail(dat, n = 8)
```

```{r}
#| label: fig-indepenent
#| fig.width: 5
#| fig.height: 5
#| fig.cap: "A scatterplot of percent of target population living alone, by UC Census Bureau data."
# this is a comment

plot(percent ~ year, dat, subset = milestone == "independent")
```

```{r}
#| label: fig-indepenent-fancy
#| fig.width: 5
#| fig.height: 5
#| fig.cap: "A barplot of percent of target population living alone, by UC Census Bureau data. The option `xpd = FALSE` will clip the bars at the vertical axis minimum."
barplot(percent ~ year, dat, subset = milestone == "independent", ylim = c(30, 100), xpd = FALSE)
box()
```

```{r}
#| label: fig-indepenent-fancier
#| fig.width: 5
#| fig.height: 5
#| fig.cap: "A connected line graph of percent of target population living alone, by UC Census Bureau data."
plot(percent ~ year, dat, subset = milestone == "independent", type = 'l', xlim = c(1980, 2025), ylim = c(0, 100), las = 1)
```
```{r}
#| label: fig-independent-fanciest
#| fig.width: 5
#| fig.height: 5
#| fig.cap: "A connected line graph of percent of target population living alone, by UC Census Bureau data. We have added annotation."
par(mfrow = c(1, 1), mar = c(4.1, 5.1, 1.6, 0.8), xaxs = "i", yaxs = "i")
plot(percent ~ year, dat, subset = milestone == "independent", type = 'b', xlim = c(1980, 2025), ylim = c(0, 100), las = 1, xlab = "", ylab = "", lwd = 2, pch = 19)
mtext("Time (Years)", side = 1, line = 2.5, font = 2, cex = 1.25)
mtext("Percent living Independently", side = 2, line = 2.5, font = 2, cex = 1.25)
mtext("Metrics of Adulthood", side = 3, line = 0, font = 2, cex = 1.5)
grid()
box()
```

```{r}
#| label: fig-independent-fanciester
#| fig.width: 5
#| fig.height: 5
#| fig.cap: "A connected line graph of percent of target population living alone, by UC Census Bureau data.  We have added additional annotation."

par(mfrow = c(1, 1), mar = c(4.1, 5.1, 1.6, 0.8), xaxs = "i", yaxs = "i")
plot(percent ~ year, dat, subset = milestone == "independent", type = 'o', xlim = c(1980, 2025), ylim = c(0, 100), las = 1, xlab = "", ylab = "", lwd = 2, pch = 19, axes = FALSE)
axis(1, at = seq(1983, 2023, by = 10))
axis(2, at = (0:10)*10, las = 1)
mtext("Time (Years)", side = 1, line = 2.5, font = 2, cex = 1.25)
mtext("Percent living Independently", side = 2, line = 2.5, font = 2, cex = 1.25)
mtext("Metrics of Adulthood", side = 3, line = 0, font = 2, cex = 1.5)
grid()
box()
```
```{r}
#| label: fig-two-by-two
#| fig.width: 5
#| fig.height: 5
#| fig.cap: "A connected line graph for percent of target population meeting four independently-determined metrics of adulthood, by UC Census Bureau data."

par(mfrow = c(2, 2), mar = c(4.1, 5.1, 1.6, 0.8), xaxs = "i", yaxs = "i")
plot(percent ~ year, dat, subset = milestone == "independent", type = 'o', xlim = c(1980, 2025), ylim = c(0, 100), las = 1, xlab = "", ylab = "", lwd = 2, pch = 19)
mtext("Percent", side = 2, line = 2.5, font = 2, cex = 1.25)
mtext("Living Independently", side = 3, line = 0.5, font = 2, cex = 1.5)

plot(percent ~ year, dat, subset = milestone == "married", type = 'o', xlim = c(1980, 2025), ylim = c(0, 100), las = 1, xlab = "", ylab = "", lwd = 2, pch = 19)
mtext("Married", side = 3, line = 0, font = 2, cex = 1.5)

plot(percent ~ year, dat, subset = milestone == "child", type = 'o', xlim = c(1980, 2025), ylim = c(0, 100), las = 1, xlab = "", ylab = "", lwd = 2, pch = 19)
mtext("Time (Years)", side = 1, line = 2.5, font = 2, cex = 1.25)
mtext("Percent", side = 2, line = 2.5, font = 2, cex = 1.25)
mtext("With Children", side = 3, line = 0, font = 2, cex = 1.5)

plot(percent ~ year, dat, subset = milestone == "home", type = 'o', xlim = c(1980, 2025), ylim = c(0, 100), las = 1, xlab = "", ylab = "", lwd = 2, pch = 19)
mtext("Time (Years)", side = 1, line = 2.5, font = 2, cex = 1.25)
mtext("Homeowner", side = 3, line = 0, font = 2, cex = 1.5)
```

```{r}
#| label: fig-superimposed
#| fig.width: 5
#| fig.height: 5
#| fig.cap: "Connected line graphs for percent of target population meeting four independently-determined metrics of adulthood, by UC Census Bureau data."

plot(percent ~ year, dat, subset = milestone == "independent", ylim = c(0, 100), type = 'l', lwd = 2, col = hcl.colors(4)[1])
lines(percent ~ year, dat, subset = milestone == "married", type = 'l', lwd = 2, col = hcl.colors(4)[2])
lines(percent ~ year, dat, subset = milestone == "child", type = 'l', lwd = 2, col = hcl.colors(4)[3])
lines(percent ~ year, dat, subset = milestone == "home", type = 'l', lwd = 2, col = hcl.colors(4)[4])
legend("bottomleft", c("Independent", "Married", "Child", "Home"), lty = 1, lwd = 2, col = hcl.colors(4))
```
## Exponential growth and decay

Read in the data in `exponential.csv`. My convention is usually calling data `dat`, but I don't normally *mix* datasets in a file like this. Maybe call this one `dat2`.

## Mouse-elephant curve

Read in the data in `mouse.csv` as `dat3` or something equally convenient. Just remember the variable name can't start with a number and shouldn't contain special characters - definitely no dashes or spaces.
