From 86a0b87b9d37c11d68e116677dcd0b7625b151a1 Mon Sep 17 00:00:00 2001 From: Elizabeth Humphries Date: Wed, 18 Sep 2024 15:30:34 -0400 Subject: [PATCH 1/7] update dataset for Rstudio lab --- modules/RStudio/lab/RStudio_Lab_Key.Rmd | 26 +++++++++---------------- 1 file changed, 9 insertions(+), 17 deletions(-) diff --git a/modules/RStudio/lab/RStudio_Lab_Key.Rmd b/modules/RStudio/lab/RStudio_Lab_Key.Rmd index 2588ca35..347934ab 100644 --- a/modules/RStudio/lab/RStudio_Lab_Key.Rmd +++ b/modules/RStudio/lab/RStudio_Lab_Key.Rmd @@ -33,25 +33,19 @@ You may be asked a question in the console when you do this. If so, answer by ty ### 0.3 -Now install a package that the instructors made that is not on CRAN but on GitHub, by copy and pasting the code into the console: - -install_github("fhdsl/dasehr") - -You may be asked a question in the console when you do this. If so, answer by typing Yes into the console. - -### 0.4 - The gray area below is a code chunk that will set up our packages and data (this will not show up in the rendered report when we press knit). You can also run the code within the editor area by pressing the green play button. Don't worry right now about what the code is doing, we will cover this later. We just want you to get used to RStudio and RMarkdowns. +This dataset is one we'll be working with quite a lot in the lectures. It contains county-level data about ER visits for heat-related illnesses in Colorado for the years 2011-2022. + ```{r setup, message=FALSE} knitr::opts_chunk$set(echo = TRUE) -library(dasehr) +library(readr) library(ggplot2) library(dplyr) -ER <- CO_heat_ER_bygender +er <- read_csv(file = "https://daseh.org/data/CO_ER_heat_visits.csv") # keep non-missing data -ER_2 <- ER %>% +er_2 <- er %>% filter(!is.na(rate)) ``` @@ -69,7 +63,7 @@ You can embed an R code chunk like this: Try pressing the green play button to s ```{r plot, out.width = "100%"} # keep only some counties -ER_3 <- ER_2 %>% +er_3 <- er_2 %>% filter(county %in% c("Arapahoe", "Denver", "Jefferson", "Larimer")) palette <- c( @@ -79,15 +73,14 @@ palette <- c( Larimer = "purple" ) -ggplot(aes(x = year, y = rate, colour = county, group = county), data = ER_3) + +ggplot(aes(x = year, y = rate, colour = county, group = county), data = er_3) + geom_line() + - facet_wrap(~gender) + scale_colour_manual(values = palette) ``` ```{r out.width = "100%", label = '0response'} # keep only some counties -ER_3 <- ER_2 %>% +er_3 <- er_2 %>% filter(county %in% c("Arapahoe", "Denver", "Jefferson", "Larimer")) palette <- c( @@ -97,9 +90,8 @@ palette <- c( Larimer = "salmon" ) -ggplot(aes(x = year, y = rate, colour = county, group = county), data = ER_3) + +ggplot(aes(x = year, y = rate, colour = county, group = county), data = er_3) + geom_line() + - facet_wrap(~gender) + scale_colour_manual(values = palette) ``` From 1a7a182ee6730d56bc1262a61c9b827825c0d51f Mon Sep 17 00:00:00 2001 From: Elizabeth Humphries Date: Wed, 18 Sep 2024 15:37:08 -0400 Subject: [PATCH 2/7] update the lab as well as the key --- modules/RStudio/lab/RStudio_Lab.Rmd | 36 +++++++++++++++++------------ 1 file changed, 21 insertions(+), 15 deletions(-) diff --git a/modules/RStudio/lab/RStudio_Lab.Rmd b/modules/RStudio/lab/RStudio_Lab.Rmd index 124d6861..347934ab 100644 --- a/modules/RStudio/lab/RStudio_Lab.Rmd +++ b/modules/RStudio/lab/RStudio_Lab.Rmd @@ -1,5 +1,5 @@ --- -title: "Starting with R and RMarkdown" +title: "Starting with R and RMarkdown - Key" output: html_document editor_options: chunk_output_type: console @@ -33,25 +33,19 @@ You may be asked a question in the console when you do this. If so, answer by ty ### 0.3 -Now install a package that the instructors made that is not on CRAN but on GitHub, by copy and pasting the code into the console: - -install_github("fhdsl/dasehr") - -You may be asked a question in the console when you do this. If so, answer by typing Yes into the console. - -### 0.4 - The gray area below is a code chunk that will set up our packages and data (this will not show up in the rendered report when we press knit). You can also run the code within the editor area by pressing the green play button. Don't worry right now about what the code is doing, we will cover this later. We just want you to get used to RStudio and RMarkdowns. +This dataset is one we'll be working with quite a lot in the lectures. It contains county-level data about ER visits for heat-related illnesses in Colorado for the years 2011-2022. + ```{r setup, message=FALSE} knitr::opts_chunk$set(echo = TRUE) -library(dasehr) +library(readr) library(ggplot2) library(dplyr) -ER <- CO_heat_ER_bygender +er <- read_csv(file = "https://daseh.org/data/CO_ER_heat_visits.csv") # keep non-missing data -ER_2 <- ER %>% +er_2 <- er %>% filter(!is.na(rate)) ``` @@ -69,7 +63,7 @@ You can embed an R code chunk like this: Try pressing the green play button to s ```{r plot, out.width = "100%"} # keep only some counties -ER_3 <- ER_2 %>% +er_3 <- er_2 %>% filter(county %in% c("Arapahoe", "Denver", "Jefferson", "Larimer")) palette <- c( @@ -79,14 +73,26 @@ palette <- c( Larimer = "purple" ) -ggplot(aes(x = year, y = rate, colour = county, group = county), data = ER_3) + +ggplot(aes(x = year, y = rate, colour = county, group = county), data = er_3) + geom_line() + - facet_wrap(~gender) + scale_colour_manual(values = palette) ``` ```{r out.width = "100%", label = '0response'} +# keep only some counties +er_3 <- er_2 %>% + filter(county %in% c("Arapahoe", "Denver", "Jefferson", "Larimer")) +palette <- c( + Arapahoe = "red", + Denver = "darkgreen", + Jefferson = "orange", + Larimer = "salmon" +) + +ggplot(aes(x = year, y = rate, colour = county, group = county), data = er_3) + + geom_line() + + scale_colour_manual(values = palette) ``` From 4ef3bb1f12dbecb072e603387beca6877aa0fde8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?ava=20=F0=9F=8C=B1?= Date: Fri, 20 Sep 2024 15:14:59 -0400 Subject: [PATCH 3/7] Update modules/RStudio/lab/RStudio_Lab_Key.Rmd --- modules/RStudio/lab/RStudio_Lab_Key.Rmd | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/modules/RStudio/lab/RStudio_Lab_Key.Rmd b/modules/RStudio/lab/RStudio_Lab_Key.Rmd index 347934ab..137c101e 100644 --- a/modules/RStudio/lab/RStudio_Lab_Key.Rmd +++ b/modules/RStudio/lab/RStudio_Lab_Key.Rmd @@ -39,9 +39,7 @@ This dataset is one we'll be working with quite a lot in the lectures. It contai ```{r setup, message=FALSE} knitr::opts_chunk$set(echo = TRUE) -library(readr) -library(ggplot2) -library(dplyr) +library(tidyverse) er <- read_csv(file = "https://daseh.org/data/CO_ER_heat_visits.csv") # keep non-missing data From 8a4ffb062ee8c18d8ce3ee0b722d74440c589d47 Mon Sep 17 00:00:00 2001 From: avahoffman Date: Fri, 20 Sep 2024 15:17:47 -0400 Subject: [PATCH 4/7] Revert changes to lab --- modules/RStudio/lab/RStudio_Lab_Key.Rmd | 28 +++++++++++++++++-------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/modules/RStudio/lab/RStudio_Lab_Key.Rmd b/modules/RStudio/lab/RStudio_Lab_Key.Rmd index 137c101e..2588ca35 100644 --- a/modules/RStudio/lab/RStudio_Lab_Key.Rmd +++ b/modules/RStudio/lab/RStudio_Lab_Key.Rmd @@ -33,17 +33,25 @@ You may be asked a question in the console when you do this. If so, answer by ty ### 0.3 -The gray area below is a code chunk that will set up our packages and data (this will not show up in the rendered report when we press knit). You can also run the code within the editor area by pressing the green play button. Don't worry right now about what the code is doing, we will cover this later. We just want you to get used to RStudio and RMarkdowns. +Now install a package that the instructors made that is not on CRAN but on GitHub, by copy and pasting the code into the console: + +install_github("fhdsl/dasehr") + +You may be asked a question in the console when you do this. If so, answer by typing Yes into the console. + +### 0.4 -This dataset is one we'll be working with quite a lot in the lectures. It contains county-level data about ER visits for heat-related illnesses in Colorado for the years 2011-2022. +The gray area below is a code chunk that will set up our packages and data (this will not show up in the rendered report when we press knit). You can also run the code within the editor area by pressing the green play button. Don't worry right now about what the code is doing, we will cover this later. We just want you to get used to RStudio and RMarkdowns. ```{r setup, message=FALSE} knitr::opts_chunk$set(echo = TRUE) -library(tidyverse) +library(dasehr) +library(ggplot2) +library(dplyr) -er <- read_csv(file = "https://daseh.org/data/CO_ER_heat_visits.csv") +ER <- CO_heat_ER_bygender # keep non-missing data -er_2 <- er %>% +ER_2 <- ER %>% filter(!is.na(rate)) ``` @@ -61,7 +69,7 @@ You can embed an R code chunk like this: Try pressing the green play button to s ```{r plot, out.width = "100%"} # keep only some counties -er_3 <- er_2 %>% +ER_3 <- ER_2 %>% filter(county %in% c("Arapahoe", "Denver", "Jefferson", "Larimer")) palette <- c( @@ -71,14 +79,15 @@ palette <- c( Larimer = "purple" ) -ggplot(aes(x = year, y = rate, colour = county, group = county), data = er_3) + +ggplot(aes(x = year, y = rate, colour = county, group = county), data = ER_3) + geom_line() + + facet_wrap(~gender) + scale_colour_manual(values = palette) ``` ```{r out.width = "100%", label = '0response'} # keep only some counties -er_3 <- er_2 %>% +ER_3 <- ER_2 %>% filter(county %in% c("Arapahoe", "Denver", "Jefferson", "Larimer")) palette <- c( @@ -88,8 +97,9 @@ palette <- c( Larimer = "salmon" ) -ggplot(aes(x = year, y = rate, colour = county, group = county), data = er_3) + +ggplot(aes(x = year, y = rate, colour = county, group = county), data = ER_3) + geom_line() + + facet_wrap(~gender) + scale_colour_manual(values = palette) ``` From df517dcecd38dd94c39c936865614419ecaf6e63 Mon Sep 17 00:00:00 2001 From: avahoffman Date: Fri, 20 Sep 2024 15:18:02 -0400 Subject: [PATCH 5/7] Revert "Revert changes to lab" This reverts commit 8a4ffb062ee8c18d8ce3ee0b722d74440c589d47. --- modules/RStudio/lab/RStudio_Lab_Key.Rmd | 28 ++++++++----------------- 1 file changed, 9 insertions(+), 19 deletions(-) diff --git a/modules/RStudio/lab/RStudio_Lab_Key.Rmd b/modules/RStudio/lab/RStudio_Lab_Key.Rmd index 2588ca35..137c101e 100644 --- a/modules/RStudio/lab/RStudio_Lab_Key.Rmd +++ b/modules/RStudio/lab/RStudio_Lab_Key.Rmd @@ -33,25 +33,17 @@ You may be asked a question in the console when you do this. If so, answer by ty ### 0.3 -Now install a package that the instructors made that is not on CRAN but on GitHub, by copy and pasting the code into the console: - -install_github("fhdsl/dasehr") - -You may be asked a question in the console when you do this. If so, answer by typing Yes into the console. - -### 0.4 - The gray area below is a code chunk that will set up our packages and data (this will not show up in the rendered report when we press knit). You can also run the code within the editor area by pressing the green play button. Don't worry right now about what the code is doing, we will cover this later. We just want you to get used to RStudio and RMarkdowns. +This dataset is one we'll be working with quite a lot in the lectures. It contains county-level data about ER visits for heat-related illnesses in Colorado for the years 2011-2022. + ```{r setup, message=FALSE} knitr::opts_chunk$set(echo = TRUE) -library(dasehr) -library(ggplot2) -library(dplyr) +library(tidyverse) -ER <- CO_heat_ER_bygender +er <- read_csv(file = "https://daseh.org/data/CO_ER_heat_visits.csv") # keep non-missing data -ER_2 <- ER %>% +er_2 <- er %>% filter(!is.na(rate)) ``` @@ -69,7 +61,7 @@ You can embed an R code chunk like this: Try pressing the green play button to s ```{r plot, out.width = "100%"} # keep only some counties -ER_3 <- ER_2 %>% +er_3 <- er_2 %>% filter(county %in% c("Arapahoe", "Denver", "Jefferson", "Larimer")) palette <- c( @@ -79,15 +71,14 @@ palette <- c( Larimer = "purple" ) -ggplot(aes(x = year, y = rate, colour = county, group = county), data = ER_3) + +ggplot(aes(x = year, y = rate, colour = county, group = county), data = er_3) + geom_line() + - facet_wrap(~gender) + scale_colour_manual(values = palette) ``` ```{r out.width = "100%", label = '0response'} # keep only some counties -ER_3 <- ER_2 %>% +er_3 <- er_2 %>% filter(county %in% c("Arapahoe", "Denver", "Jefferson", "Larimer")) palette <- c( @@ -97,9 +88,8 @@ palette <- c( Larimer = "salmon" ) -ggplot(aes(x = year, y = rate, colour = county, group = county), data = ER_3) + +ggplot(aes(x = year, y = rate, colour = county, group = county), data = er_3) + geom_line() + - facet_wrap(~gender) + scale_colour_manual(values = palette) ``` From d1f850899540e911e0f370f828a9c1b06dff8a5f Mon Sep 17 00:00:00 2001 From: avahoffman Date: Fri, 20 Sep 2024 15:18:38 -0400 Subject: [PATCH 6/7] Revert changes in blank file (whoops did the wrong one originally) --- modules/RStudio/lab/RStudio_Lab.Rmd | 36 ++++++++++++----------------- 1 file changed, 15 insertions(+), 21 deletions(-) diff --git a/modules/RStudio/lab/RStudio_Lab.Rmd b/modules/RStudio/lab/RStudio_Lab.Rmd index 347934ab..124d6861 100644 --- a/modules/RStudio/lab/RStudio_Lab.Rmd +++ b/modules/RStudio/lab/RStudio_Lab.Rmd @@ -1,5 +1,5 @@ --- -title: "Starting with R and RMarkdown - Key" +title: "Starting with R and RMarkdown" output: html_document editor_options: chunk_output_type: console @@ -33,19 +33,25 @@ You may be asked a question in the console when you do this. If so, answer by ty ### 0.3 -The gray area below is a code chunk that will set up our packages and data (this will not show up in the rendered report when we press knit). You can also run the code within the editor area by pressing the green play button. Don't worry right now about what the code is doing, we will cover this later. We just want you to get used to RStudio and RMarkdowns. +Now install a package that the instructors made that is not on CRAN but on GitHub, by copy and pasting the code into the console: + +install_github("fhdsl/dasehr") + +You may be asked a question in the console when you do this. If so, answer by typing Yes into the console. -This dataset is one we'll be working with quite a lot in the lectures. It contains county-level data about ER visits for heat-related illnesses in Colorado for the years 2011-2022. +### 0.4 + +The gray area below is a code chunk that will set up our packages and data (this will not show up in the rendered report when we press knit). You can also run the code within the editor area by pressing the green play button. Don't worry right now about what the code is doing, we will cover this later. We just want you to get used to RStudio and RMarkdowns. ```{r setup, message=FALSE} knitr::opts_chunk$set(echo = TRUE) -library(readr) +library(dasehr) library(ggplot2) library(dplyr) -er <- read_csv(file = "https://daseh.org/data/CO_ER_heat_visits.csv") +ER <- CO_heat_ER_bygender # keep non-missing data -er_2 <- er %>% +ER_2 <- ER %>% filter(!is.na(rate)) ``` @@ -63,7 +69,7 @@ You can embed an R code chunk like this: Try pressing the green play button to s ```{r plot, out.width = "100%"} # keep only some counties -er_3 <- er_2 %>% +ER_3 <- ER_2 %>% filter(county %in% c("Arapahoe", "Denver", "Jefferson", "Larimer")) palette <- c( @@ -73,26 +79,14 @@ palette <- c( Larimer = "purple" ) -ggplot(aes(x = year, y = rate, colour = county, group = county), data = er_3) + +ggplot(aes(x = year, y = rate, colour = county, group = county), data = ER_3) + geom_line() + + facet_wrap(~gender) + scale_colour_manual(values = palette) ``` ```{r out.width = "100%", label = '0response'} -# keep only some counties -er_3 <- er_2 %>% - filter(county %in% c("Arapahoe", "Denver", "Jefferson", "Larimer")) -palette <- c( - Arapahoe = "red", - Denver = "darkgreen", - Jefferson = "orange", - Larimer = "salmon" -) - -ggplot(aes(x = year, y = rate, colour = county, group = county), data = er_3) + - geom_line() + - scale_colour_manual(values = palette) ``` From 5153b26ba9ca08bb41543211fcd9166ab525e613 Mon Sep 17 00:00:00 2001 From: avahoffman Date: Thu, 26 Sep 2024 13:19:41 -0400 Subject: [PATCH 7/7] Remove installation step (covered in Basic R) --- modules/RStudio/lab/RStudio_Lab_Key.Rmd | 57 +++++-------------------- 1 file changed, 11 insertions(+), 46 deletions(-) diff --git a/modules/RStudio/lab/RStudio_Lab_Key.Rmd b/modules/RStudio/lab/RStudio_Lab_Key.Rmd index 137c101e..90b3cb6a 100644 --- a/modules/RStudio/lab/RStudio_Lab_Key.Rmd +++ b/modules/RStudio/lab/RStudio_Lab_Key.Rmd @@ -5,40 +5,15 @@ editor_options: chunk_output_type: console --- -## R Markdown +# R Markdown -Please read through everything and then try the exercises. +Please read through everything and then try the exercises. This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see . The way you can create a file like this in RStudio is: File → New File → R Markdown and then using the default or using a template. -This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see . +### The Code -The way you can create a file like this in RStudio is: File → New File → R Markdown and then using the default or using a template. - -Now we will install some packages! Note it may take ~5-10 minutes to run all these steps. **You need to run these steps in the order listed.** - -### 0.1 - -First copy and paste the following code into the console (the lower left panel/pane): -install.packages("remotes") - -This code will install a package from CRAN called "remotes".
-You may be asked a question in the console when you do this. If so, answer by typing Yes into the console. - -### 0.2 - -Next copy and paste the following code again into the console (the lower left panel/pane): -library(remotes) - -This code loads the remotes package into memory- in other words we can use the functions within the package.
-You may be asked a question in the console when you do this. If so, answer by typing Yes into the console. - -### 0.3 - -The gray area below is a code chunk that will set up our packages and data (this will not show up in the rendered report when we press knit). You can also run the code within the editor area by pressing the green play button. Don't worry right now about what the code is doing, we will cover this later. We just want you to get used to RStudio and RMarkdowns. - -This dataset is one we'll be working with quite a lot in the lectures. It contains county-level data about ER visits for heat-related illnesses in Colorado for the years 2011-2022. +The gray area below is a code chunk that will set up our packages and data. You can also run the code within the editor area by pressing the green play button. Don't worry right now about what the code is doing, we will cover this later. We just want you to get used to RStudio and RMarkdowns. This dataset is one we'll be working with quite a lot in the lectures. It contains county-level data about ER visits for heat-related illnesses in Colorado for the years 2011-2022. ```{r setup, message=FALSE} -knitr::opts_chunk$set(echo = TRUE) library(tidyverse) er <- read_csv(file = "https://daseh.org/data/CO_ER_heat_visits.csv") @@ -47,17 +22,11 @@ er_2 <- er %>% filter(!is.na(rate)) ``` -When you click the **Knit** button (at the top of RStudio), a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. -Next we will show you some code - no worries about understanding it yet, we just want to get you familiar with where code goes. +When you click the **Knit** button (at the top of RStudio), a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. Next we will show you some code - no worries about understanding it yet, we just want to get you familiar with where code goes. When code is in an RMarkdown file chunk, it is saved to a file. When it is in the console, it is not saved. The console is useful for installing packages like we just did, this is because we only need to do it once, so we don't usually need to save the code. -When code is in an RMarkdown file chunk, it is saved to a file. When it is in the console, it is not saved. +### Plotting some data -The console is useful for installing packages like we just did, this is because we only need to do it once, so we don't usually need to save the code. - -## Plotting some data - -Here is code that will make a plot of some data. -You can embed an R code chunk like this: Try pressing the green play button to see what happens. Make sure you have run the previous code chunk first by pressing the green play button in that chunk. +Here is code that will make a plot of some data.You can embed an R code chunk like this: Try pressing the green play button to see what happens. Make sure you have run the previous code chunk first by pressing the green play button in that chunk. ```{r plot, out.width = "100%"} # keep only some counties @@ -94,25 +63,24 @@ ggplot(aes(x = year, y = rate, colour = county, group = county), data = er_3) + ``` -## Exercise +# Exercise Here are a few changes that will show you how to change small things in `R` code and the output it makes. After each change, hit the **Knit** button again. - - ### 1.1 Go through the code for the plot above and change the colors in `palette` to something other than what they originally were. See http://www.stat.columbia.edu/~tzheng/files/Rcolor.pdf for a large list of colors. For example, you could replace blue with red. ### 1.2 -Add a new R chunk below the following chunk. You can use the insert chunk button or copy paste an existing code chunk. Include a lowercase x inside the chunk as the code. Make sure you press the knit button after this to see what the new chunk looks like. - +Add a new R chunk after ``. You can use the insert chunk button or copy paste an existing code chunk. Include a lowercase x inside the chunk as the code. Make sure you press the knit button after this to see what the new chunk looks like. ```{r} x <- c(1, 2, 3) ``` + + # Practice on Your Own! ### P.1 @@ -122,6 +90,3 @@ Update the options of the R chunk you just made (with the lowercase x in it) so ### P.2 Create another R Markdown Document from RStudio dropdowns: File → New File → R Markdown. - - -