---
title: "Midsemester Review (Notes)"
format:
  html:
    toc: true
    toc-depth: 2
    embed-resources: true
---

```{r include = FALSE}
# This chunk just sets up some styling (eg: default size of our images)
knitr::opts_chunk$set(
  collapse = TRUE, 
  warning = FALSE,
  message = FALSE,
  fig.height = 2.75, 
  fig.width = 4.25,
  fig.align = 'center')
```

::: {.callout-note title="Learning goals"}
Review the basics of wrangling and visualization
:::

## Warm-up

![](https://mac-stat.github.io/images/112/legos.png)

Thus far, we've learned how to:

-   use `ggplot()` to construct data visualizations
-   do some wrangling:
    -   `arrange()` our data in a meaningful order
    -   subset the data to only `filter()` the rows and `select()` the columns of interest
    -   `mutate()` existing variables and define new variables
    -   `summarize()` various aspects of a variable, both overall and by group (`group_by()`)
-   reshape our data to fit the task at hand (`pivot_longer()`, `pivot_wider()`)
-   `join()` different datasets into one

Let's review some basics, emphasizing some themes in Homework 3 feedback! Along the way, pay special attention to formatting your code: code is communication.

\
\
\
\

**EXAMPLE 1: Make a plot**

Recall our data on hiking the "high peaks" in the Adirondack Mountains of northern New York state. This includes data on the hike’s highest elevation (feet), vertical ascent (feet), length (miles), time in hours that it takes to complete, and difficulty rating.

```{r}
library(tidyverse)

hikes <- read.csv("https://mac-stat.github.io/data/high_peaks.csv")
```

Construct a plot that allows us to examine how vertical ascent varies from hike to hike.

```{r}

```

\
\
\
\

**EXAMPLE 2: What's wrong?**

Critique the following interpretation of the above plot:

"The typical ascent is around 3000 feet."

\
\
\
\

**EXAMPLE 3: Captions, axis labels, and titles**

Critique the use of the axis labels, caption, and title here. Then make a better version.

```{r fig.cap = "A density plot of the vertical ascent of a hike, in feet"}
ggplot(hikes, aes(x = ascent)) + 
  geom_density() + 
  labs(x = "the vertical ascent of a hike in feet",
       title = "Density plot of hike vertical ascent")
```

\
\
\
\

**EXAMPLE 4: Wrangling practice -- one verb**

```{r}
# How many hikes are in the dataset?


# What's the maximum elevation among the hikes?


# How many hikes are there of each rating?


# What hikes have elevations above 5000 ft?


```

\
\
\
\

**EXAMPLE 5: Wrangling practice -- multiple verbs**

```{r}
# What's the average hike length for each rating category?


# What's the average length of *only* the easy hikes


# What 6 hikes take the longest time to complete?


# What 6 hikes take the longest time per mile?


```

\
\
\
\

## Midterm assessment

We will have a quiz next Tuesday, one week from today. Unlike the course project which will assess your deeper conceptual understanding of the course material, and your ability to build upon this in new settings, the quiz will assess your grasp on the foundations (eg: wrangling and visualization code and output).

Preparing for and completing this assessment is important to solidifying your understanding of these foundations before moving on to our final unit and course project.

\
\

**Content**

The quiz will cover activities 1-11, as labeled on the online course manual.

In general, the exercises will cover a variety of angles. For example...

-   What does this result *mean* in context?\
    You'll be given some visualization / wrangling results and asked to interpret them.

-   What *code* is necessary to completing the task at hand?\
    You'll be given a task and asked for the necessary code.

-   What does this code *do*?\
    You'll be given some code without output and asked to anticipate the result.

\
\

**Structure**

Review the quiz practice for details.

\
\
\
\
