Skip to content

Commit

Permalink
update_factors_lab_lecture
Browse files Browse the repository at this point in the history
  • Loading branch information
ehumph committed Dec 5, 2024
1 parent 6ce432c commit 630251d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
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

0 comments on commit 630251d

Please sign in to comment.