From 630251dd1b706f8e01fb09fa261f66523c336543 Mon Sep 17 00:00:00 2001 From: Elizabeth Humphries Date: Thu, 5 Dec 2024 15:52:54 -0500 Subject: [PATCH] update_factors_lab_lecture --- modules/Factors/Factors.Rmd | 10 +++++----- modules/Factors/lab/Factors_Lab_Key.Rmd | 10 +++++----- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/modules/Factors/Factors.Rmd b/modules/Factors/Factors.Rmd index e5bceed8..956ee8e3 100644 --- a/modules/Factors/Factors.Rmd +++ b/modules/Factors/Factors.Rmd @@ -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 ``` @@ -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) ``` @@ -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) ``` @@ -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) @@ -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) diff --git a/modules/Factors/lab/Factors_Lab_Key.Rmd b/modules/Factors/lab/Factors_Lab_Key.Rmd index 75721109..d6f65091 100644 --- a/modules/Factors/lab/Factors_Lab_Key.Rmd +++ b/modules/Factors/lab/Factors_Lab_Key.Rmd @@ -13,7 +13,7 @@ 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. @@ -21,7 +21,7 @@ Load the CalEnviroScreen dataset and use `select` to choose the `CaliforniaCount 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 @@ -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() ``` @@ -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 %>% @@ -113,7 +113,7 @@ library(forcats) ces_Ventura_plot <- ces_Ventura %>% drop_na() %>% - ggplot(mapping = aes( + ggplot(aes( x = fct_reorder( ZIP, med_ImpWaterBodies ),