Skip to content

Commit

Permalink
adding the labs for RStudio to be more like sisbid
Browse files Browse the repository at this point in the history
  • Loading branch information
carriewright11 committed Sep 30, 2024
1 parent 715ea77 commit 6295660
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 18 deletions.
38 changes: 23 additions & 15 deletions modules/RStudio/lab/RStudio_Lab.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -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 <http://rmarkdown.rstudio.com>. 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)
Expand All @@ -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"))
Expand All @@ -37,38 +45,38 @@ 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) +
geom_line() +
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 `<!-- Your code chunk goes here -->`. 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 `<!-- Your code chunk goes here -->`. 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)
```

<!-- Your code chunk goes here -->



# 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.
12 changes: 9 additions & 3 deletions modules/RStudio/lab/RStudio_Lab_Key.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -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 <http://rmarkdown.rstudio.com>. 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

Expand All @@ -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
Expand Down Expand Up @@ -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

0 comments on commit 6295660

Please sign in to comment.