diff --git a/modules/RStudio/lab/RStudio_Lab.Rmd b/modules/RStudio/lab/RStudio_Lab.Rmd index 9604d9f3..7ee49ada 100644 --- a/modules/RStudio/lab/RStudio_Lab.Rmd +++ b/modules/RStudio/lab/RStudio_Lab.Rmd @@ -9,10 +9,14 @@ editor_options: 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. +1. Try compiling this document using the “Knit HTML” button. What files are produced? + ### The Code 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. +2. Press the green play button. What happens? + ```{r setup, message=FALSE} library(tidyverse) @@ -28,7 +32,11 @@ When you click the **Knit** button (at the top of RStudio), a document will be g 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%"} +3. Try the "run all chunks above" button that is to the left of the play button on the following chunk. What happens? + +4. Then press the play button on this same chunk. What happens? + +```{r out.width = "100%"} # keep only some counties er_3 <- er_2 %>% filter(county %in% c("Arapahoe", "Denver", "Jefferson", "Larimer")) @@ -37,7 +45,7 @@ palette <- c( Arapahoe = "blue", Denver = "darkgreen", Jefferson = "orange", - Larimer = "purple" + Larimer = "salmon" ) ggplot(aes(x = year, y = rate, colour = county, group = county), data = er_3) + @@ -45,20 +53,9 @@ ggplot(aes(x = year, y = rate, colour = county, group = county), data = er_3) + scale_colour_manual(values = palette) ``` +### Adding new chunks - - -# 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 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. +5. 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) @@ -66,9 +63,20 @@ x <- c(1, 2, 3) + + # Practice on Your Own! +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. ### P.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. + +### P.2 + Create another R Markdown Document from RStudio dropdowns: File → New File → R Markdown. + +### P.3 + +Add a new header with two hash symbols `##` at the start of a line with some text. Knit the report to see how it looks. diff --git a/modules/RStudio/lab/RStudio_Lab_Key.Rmd b/modules/RStudio/lab/RStudio_Lab_Key.Rmd index c6cba0b4..79ee8f3d 100644 --- a/modules/RStudio/lab/RStudio_Lab_Key.Rmd +++ b/modules/RStudio/lab/RStudio_Lab_Key.Rmd @@ -9,7 +9,7 @@ editor_options: 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. -1.Try compiling this document using the “Knit HTML” button. What files are produced? +1. Try compiling this document using the “Knit HTML” button. What files are produced? ### The Code @@ -32,9 +32,9 @@ When you click the **Knit** button (at the top of RStudio), a document will be g 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. -3. Try the play all previous button that is to the left of the play button on the following chunk. What happens? +3. Try the "run all chunks above" button that is to the left of the play button on the following chunk. What happens? -4. Then press the play button. What happens? +4. Then press the play button on this same chunk. What happens? ```{r out.width = "100%"} # keep only some counties @@ -79,3 +79,9 @@ Go through the code for the plot above and change the colors in `palette` to som ### P.2 Create another R Markdown Document from RStudio dropdowns: File → New File → R Markdown. + +### P.3 + +Add a new header with two hash symbols `##` at the start of a line with some text. Knit the report to see how it looks. + +## New Header