Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Factors] update lab and lecture_Dec2024 #257

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions modules/Factors/Factors.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ Let's make a plot first.

```{r, fig.height= 3, warning = F}
er_visits_age_subset %>%
ggplot(mapping = aes(x = age, y = rate)) +
ggplot(aes(x = age, y = rate)) +
geom_boxplot() +
theme_bw(base_size = 12) # make all labels size 12
```
Expand Down Expand Up @@ -148,7 +148,7 @@ Now let's make our plot again:

```{r, fig.height= 3, warning = FALSE}
er_visits_age_fct %>%
ggplot(mapping = aes(x = age, y = rate)) +
ggplot(aes(x = age, y = rate)) +
geom_boxplot() +
theme_bw(base_size = 12)
```
Expand Down Expand Up @@ -205,7 +205,7 @@ What if we wanted to order `age` by increasing `rate`?
library(forcats)

er_visits_age_fct %>%
ggplot(mapping = aes(x = age, y = rate)) +
ggplot(aes(x = age, y = rate)) +
geom_boxplot() +
theme_bw(base_size = 12)
```
Expand All @@ -230,7 +230,7 @@ We can order a factor by another variable by using the `fct_reorder()` function
library(forcats)

er_visits_age_fct %>%
ggplot(mapping = aes(x = fct_reorder(age, rate, mean), y = rate)) +
ggplot(aes(x = fct_reorder(age, rate, mean), y = rate)) +
geom_boxplot() +
labs(x = "Age Category") +
theme_bw(base_size = 12)
Expand All @@ -242,7 +242,7 @@ er_visits_age_fct %>%
library(forcats)

er_visits_age_fct %>%
ggplot(mapping = aes(x = fct_reorder(age, rate, mean, .desc = TRUE), y = rate)) +
ggplot(aes(x = fct_reorder(age, rate, mean, .desc = TRUE), y = rate)) +
geom_boxplot() +
labs(x = "Age Category") +
theme_bw(base_size = 12)
Expand Down
10 changes: 5 additions & 5 deletions modules/Factors/lab/Factors_Lab_Key.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ library(tidyverse)

### 1.0

Load the CalEnviroScreen dataset and use `select` to choose the `CaliforniaCounty`, `ImpWaterBodies`, and `ZIP` variables. Then subset this data using `filter` to include only the California counties Napa and San Francisco. Name this data "ces".
Load the CalEnviroScreen dataset and use `select` to choose the `CaliforniaCounty`, `ImpWaterBodies`, and `ZIP` variables. Then subset this data using `filter` to include only the California counties Amador, Napa, Ventura, and San Francisco. Name this data "ces".

`ImpWaterBodies`: measure of the number of pollutants across all impaired water bodies within a given distance of populated areas.

```{r}
ces <-
read_csv("https://daseh.org/data/CalEnviroScreen_data.csv") %>%
select(CaliforniaCounty, ImpWaterBodies, ZIP) %>%
filter(CaliforniaCounty == c("Amador", "Napa", "Ventura", "San Francisco"))
filter(CaliforniaCounty %in% c("Amador", "Napa", "Ventura", "San Francisco"))
```

### 1.1
Expand All @@ -30,7 +30,7 @@ Create a boxplot showing the difference in groundwater contamination threats (`I

```{r 1.1response}
ces %>%
ggplot(mapping = aes(x = CaliforniaCounty, y = ImpWaterBodies)) +
ggplot(aes(x = CaliforniaCounty, y = ImpWaterBodies)) +
geom_boxplot()
```

Expand Down Expand Up @@ -60,7 +60,7 @@ Repeat question 1.1 and 1.2 using the "ces_fct" data. You should see different o

```{r 1.4response}
ces_fct %>%
ggplot(mapping = aes(x = CaliforniaCounty, y = ImpWaterBodies)) +
ggplot(aes(x = CaliforniaCounty, y = ImpWaterBodies)) +
geom_boxplot()

ces_fct %>%
Expand Down Expand Up @@ -113,7 +113,7 @@ library(forcats)

ces_Ventura_plot <- ces_Ventura %>%
drop_na() %>%
ggplot(mapping = aes(
ggplot(aes(
x = fct_reorder(
ZIP, med_ImpWaterBodies
),
Expand Down
Loading