-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
40fac64
commit 9571145
Showing
25 changed files
with
1,874 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
embedded_learnr <- function(url, id) { | ||
glue::glue( | ||
'<iframe ', | ||
'style="margin: 0px auto; min-width: 100%; overflow: hidden; height: 801px;" ', | ||
'id="[id]" class="interactive" src="[url]" scrolling="no" frameborder="no" ', | ||
'onload=\'iFrameResize({}, "#[id]")\'', | ||
'></iframe>', | ||
.open = "[", .close = "]" | ||
) | ||
} | ||
|
||
include_iframe_resizer <- function() { | ||
glue::glue( | ||
'<script src="https://cdnjs.cloudflare.com/ajax/libs/iframe-resizer/3.5.16/iframeResizer.min.js" type="text/javascript"></script>' | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
--- | ||
title: "Introduction to R and the tidyverse" | ||
date: "2020-05-11" | ||
--- | ||
|
||
```{r setup, include=FALSE} | ||
knitr::opts_chunk$set(fig.align = "center") | ||
``` | ||
|
||
## Part 1: The basics of R and dplyr | ||
|
||
For the first part of today's lesson, you need to work through a few of RStudio's introductory primers. You'll do these in your browser and type code and see results there. | ||
|
||
You'll learn some of the basics of R, as well as some powerful methods for manipulating data with the **dplyr** package. | ||
|
||
Complete these: | ||
|
||
- **The Basics** | ||
- [Visualization Basics](https://rstudio.cloud/learn/primers/1.1) | ||
- [Programming Basics](https://rstudio.cloud/learn/primers/1.2) | ||
- **Work with Data** | ||
- [Working with Tibbles](https://rstudio.cloud/learn/primers/2.1) | ||
- [Isolating Data with dplyr](https://rstudio.cloud/learn/primers/2.2) | ||
- [Deriving Information with dplyr](https://rstudio.cloud/learn/primers/2.3) | ||
|
||
The content from these primers comes from the (free and online!) book [*R for Data Science* by Garrett Grolemund and Hadley Wickham](https://r4ds.had.co.nz/). I highly recommend the book as a reference and for continuing to learn and use R in the future (like running regression models and other types of statistical analysis) | ||
|
||
|
||
## Part 2: Getting familiar with RStudio | ||
|
||
The RStudio primers you just worked through are a great introduction to writing and running R code, but you typically won't type code in a browser when you work with R. Instead, you'll use a nicer programming environment like RStudio, which lets you type and save code in scripts, run code from those scripts, and see the output of that code, all in the same program. | ||
|
||
To get familiar with RStudio, watch this video: | ||
|
||
<div class="ratio ratio-16x9"> | ||
<iframe src="https://www.youtube.com/embed/cnQ-v1UUWyE" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen="" frameborder="0"></iframe> | ||
</div> | ||
|
||
|
||
## Part 3: RStudio Projects | ||
|
||
One of the most powerful and useful aspects of RStudio is its ability to manage projects. | ||
|
||
When you first open R, it is "pointed" at some folder on your computer, and anything you do will be relative to that folder. The technical term for this is a "working directory." | ||
|
||
When you first open RStudio, look in the area right at the top of the Console pane to see your current working directory. Most likely you'll see something cryptic: `~/` | ||
|
||
```{r working-directory, echo=FALSE, out.width="50%"} | ||
knitr::include_graphics("/files/img/lesson/working-directory.png", error = FALSE) | ||
``` | ||
|
||
That tilde sign (`~`) is a shortcut that stands for your user directory. On Windows this is `C:\Users\your_user_name\`; on macOS this is `/Users/your_user_name/`. With the working directory set to `~/`, R is "pointed" at that folder, and anything you save will end up in that folder, and R will expect any data that you load to be there too. | ||
|
||
It's always best to point R at some other directory. If you don't use RStudio, you need to manually set the working directory to where you want it with `setwd()`, and many R scripts in the wild include something like `setwd("C:\\Users\\bill\\Desktop\\Important research project")` at the beginning to change the directory. **THIS IS BAD THOUGH** ([see here for an explanation](https://www.tidyverse.org/blog/2017/12/workflow-vs-script/)). If you ever move that directory somewhere else, or run the script on a different computer, or share the project with someone, the path will be wrong and nothing will run and you will be sad. | ||
|
||
The best way to deal with working directories with RStudio is to use RStudio Projects. These are special files that RStudio creates for you that end in a `.Rproj` extension. When you open one of these special files, a new RStudio instance will open up and be pointed at the correct directory automatically. If you move the folder later or open it on a different computer, it will work just fine and you will not be sad. | ||
|
||
[Read this super short chapter on RStudio projects.](https://r4ds.had.co.nz/workflow-projects.html) | ||
|
||
|
||
## Part 4: Getting familiar with R Markdown | ||
|
||
To ensure that the analysis and graphics you make are reproducible, you'll do the majority of your work in this class using **R Markdown** files. | ||
|
||
Do the following things: | ||
|
||
1. Watch this video: | ||
|
||
<div class="ratio ratio-16x9"> | ||
<iframe src="https://player.vimeo.com/video/178485416?color=428bca" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen="" frameborder="0"></iframe> | ||
</div> | ||
|
||
| ||
|
||
2. Skim through the content at these pages: | ||
|
||
- [Using Markdown](/resource/markdown/) | ||
- [Using R Markdown](/resource/rmarkdown/) | ||
- [How it Works](http://rmarkdown.rstudio.com/lesson-2.html) | ||
- [Code Chunks](http://rmarkdown.rstudio.com/lesson-3.html) | ||
- [Inline Code](http://rmarkdown.rstudio.com/lesson-4.html) | ||
- [Markdown Basics](http://rmarkdown.rstudio.com/lesson-8.html) (The [R Markdown Reference Guide](https://www.rstudio.com/wp-content/uploads/2015/03/rmarkdown-reference.pdf) is super useful here.) | ||
- [Output Formats](http://rmarkdown.rstudio.com/lesson-9.html) | ||
|
||
3. Watch this video: | ||
|
||
<div class="ratio ratio-16x9"> | ||
<iframe src="https://www.youtube.com/embed/fT5xI1cmE2c" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen="" frameborder="0"></iframe> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,143 @@ | ||
--- | ||
title: "Graphic design" | ||
date: "2020-05-12" | ||
--- | ||
|
||
```{r setup, include=FALSE} | ||
knitr::opts_chunk$set(fig.align = "center") | ||
``` | ||
|
||
## File types | ||
|
||
Recall from the [last section of the lecture](/slides/02-slides.html#image-types) that you'll typically work with one of two image file types: bitmap images and vector images. | ||
|
||
Bitmaps store image information as tiny squares, or pixels. Specific files types compress these images in different ways: JPEG files smudge together groups of similarly colored pixels to save repetition, while PNG and GIF files look for fields of the exact same color. | ||
|
||
```{r bitmap-example, echo=FALSE, out.width="30%"} | ||
knitr::include_graphics("/slides/img/02/example-bitmap.png", error = FALSE) | ||
``` | ||
|
||
You use bitmap images for things that go on the internet and when you place images in Word (technically modern versions of Word can handle some types of vector images, but that support isn't universal yet). | ||
|
||
Vector images, on the other hand, do not store image information as pixels. Instead, these use mathematical formulas to draw lines and curves and fill areas with specific colors. This makes them a little more complicated to draw and create, but it also means that you can scale them up or down infinitely—a vector image will look just as crisp on a postage stamp as it would on a billboard. | ||
|
||
```{r vector-example, echo=FALSE, out.width="30%"} | ||
knitr::include_graphics("/slides/img/02/example-vector.png", error = FALSE) | ||
``` | ||
|
||
Here are some general guidelines: | ||
|
||
- If an image has lots of colors (like a photograph), you should use a bitmap file type designed for lots of colors, like JPEG. This is the case regardless of where the image will ultimately end up. If you're putting it on the internet, it needs to be a JPEG. If you're blowing it up to fit on a billboard, it will still need to be a JPEG (and you have to use a fancy super high quality camera to get a high enough resolution for that kind of expansion) | ||
|
||
- If an image has a few colors and some text and is not a photograph *and* you're using the image in Word or on the internet, you should use a bitmap file type designed for carefully compressing a few colors, like PNG. | ||
|
||
- If an image has a few colors and some text and is not a photograph *and* you're planning on using it in multiple sizes (like a logo), or using it in fancier production software like Adobe InDesign (for print) or Adobe After Effects (for video), you should use a vector file type like PDF or SVG. | ||
|
||
|
||
## Select the best file type | ||
|
||
Practice deciding what kind of file type you should use by looking at these images and choosing what you think works the best. | ||
|
||
```{r include=FALSE} | ||
library(checkdown) | ||
``` | ||
|
||
<div class="question"> | ||
|
||
```{r atlanta-sign, echo=FALSE, out.width="60%"} | ||
knitr::include_graphics("/files/img/lesson/file-types/atlanta-sign.jpg", error = FALSE) | ||
``` | ||
|
||
```{r atlanta-sign-question, echo=FALSE, results="asis"} | ||
check_question("JPG", options = c("PNG", "JPG", "PDF"), type = "radio", | ||
button_label = "Check answer", question_id = 1, | ||
right = "Correct! This is a photograph, so it should be a JPG. It might seem a little tricky since there are so few colors, but it still needs to be a JPG because the black paint on the brick is actually a range of thousands of different shades of black pixels.", | ||
wrong = "Not quite—this image has a lot of colors in it…") | ||
``` | ||
|
||
</div> | ||
|
||
--- | ||
|
||
<div class="question"> | ||
|
||
```{r gsu-logo, echo=FALSE, out.width="60%"} | ||
knitr::include_graphics("/files/img/lesson/file-types/gsu-logo.png", error = FALSE) | ||
``` | ||
|
||
```{r gsu-logo-question, echo=FALSE, results="asis"} | ||
check_question(c("PNG", "PDF"), options = c("PNG", "JPG", "PDF"), type = "radio", | ||
button_label = "Check answer", question_id = 2, | ||
right = "Correct! This is a logo with a few colors in it, so it’s vector-based. If you use a PDF of the logo, you can rescale it infinitely big or small. If you use a PNG, it will work nicely online.", | ||
wrong = "Not quite—this image doesn’t have a lot of colors in it…") | ||
``` | ||
|
||
</div> | ||
|
||
--- | ||
|
||
<div class="question"> | ||
|
||
```{r pie-chart, echo=FALSE, out.width="60%"} | ||
knitr::include_graphics("/files/img/lesson/file-types/pie_chart.png", error = FALSE) | ||
``` | ||
|
||
```{r pie-chart-question, echo=FALSE, results="asis"} | ||
check_question(c("PNG", "PDF"), options = c("PNG", "JPG", "PDF"), type = "radio", | ||
button_label = "Check answer", question_id = 3, | ||
right = "Correct! This is a grpah with a few colors in it, so should be vector-based. If you’re using this in a fancy publication or report, use a PDF. If you’e using Word or HTML, use a PNG.", | ||
wrong = "Not quite—this image doesn’t have a lot of colors in it…") | ||
``` | ||
|
||
</div> | ||
|
||
--- | ||
|
||
<div class="question"> | ||
|
||
```{r solo, echo=FALSE, out.width="60%"} | ||
knitr::include_graphics("/files/img/lesson/file-types/solo.jpg", error = FALSE) | ||
``` | ||
|
||
```{r solo-question, echo=FALSE, results="asis"} | ||
check_question("JPG", options = c("PNG", "JPG", "PDF"), type = "radio", | ||
button_label = "Check answer", question_id = 4, | ||
right = "Correct! This has a ton of colors in it and is mostly a photograph. You may have been thrown off by the text in the bottom section, or the stylized shapes of the Millennium Falcon’s windows at the top. Those shapes and the text are both vector-based, but because the majority of the image is a photogrpah, it still needs to be saved as a JPG. To keep the text nice and crisp, it needs to be exported at a high resolution.", | ||
wrong = "Not quite—this image has a lot of colors in it…") | ||
``` | ||
|
||
</div> | ||
|
||
--- | ||
|
||
<div class="question"> | ||
|
||
```{r butterflies, echo=FALSE, out.width="60%"} | ||
knitr::include_graphics("/files/img/lesson/file-types/butterflies.png", error = FALSE) | ||
``` | ||
|
||
```{r butterflies-question, echo=FALSE, results="asis"} | ||
check_question(c("PNG", "PDF"), options = c("PNG", "JPG", "PDF"), type = "radio", | ||
button_label = "Check answer", question_id = 5, | ||
right = "Correct! Even though this is very colorful, it should be a PNG or PDF, since it’s vector-based and not a photograph. ", | ||
wrong = "Not quite—this image doesn’t have a lot of colors in it…") | ||
``` | ||
|
||
</div> | ||
|
||
--- | ||
|
||
<div class="question"> | ||
|
||
```{r atlanta-night, echo=FALSE, out.width="60%"} | ||
knitr::include_graphics("/files/img/lesson/file-types/atlanta-night.jpg", error = FALSE) | ||
``` | ||
|
||
```{r atlanta-night-question, echo=FALSE, results="asis"} | ||
check_question("JPG", options = c("PNG", "JPG", "PDF"), type = "radio", | ||
button_label = "Check answer", question_id = 6, | ||
right = "Correct! This is a photograph and should be a JPG.", | ||
wrong = "Not quite—this image has a lot of colors in it…") | ||
``` | ||
|
||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
--- | ||
title: "Mapping data to graphics" | ||
date: "2020-05-13" | ||
--- | ||
|
||
```{r setup, include=FALSE} | ||
knitr::opts_chunk$set(fig.align = "center") | ||
``` | ||
|
||
## Part 1: Data visualization with {ggplot2} | ||
|
||
For the first part of today's lesson, you need to work through RStudio's introductory primers for {ggplot2}. You'll do these in your browser and type code and see results there. | ||
|
||
It seems like there are a lot, but they're short and go fairly quickly (especially as you get the hang of the `ggplot()` syntax). Complete these: | ||
|
||
- **Visualize Data** | ||
- [Exploratory Data Analysis](https://rstudio.cloud/learn/primers/3.1) | ||
- [Bar Charts](https://rstudio.cloud/learn/primers/3.2) | ||
- [Histograms](https://rstudio.cloud/learn/primers/3.3) | ||
- [Boxplots and Counts](https://rstudio.cloud/learn/primers/3.4) | ||
- [Scatterplots](https://rstudio.cloud/learn/primers/3.5) | ||
- [Line plots](https://rstudio.cloud/learn/primers/3.6) | ||
- [Overplotting and Big Data](https://rstudio.cloud/learn/primers/3.7) | ||
- [Customize Your Plots](https://rstudio.cloud/learn/primers/3.8) | ||
|
||
|
||
## Part 2: Reshaping data with {tidyr} | ||
|
||
For the last part of today's lesson, you'll work through just one RStudio primer to learn how to use the {tidyr} package to reshape data from wide to long and back to wide. | ||
|
||
Complete this: | ||
|
||
- **Tidy Your Data** | ||
- [Reshape Data](https://rstudio.cloud/learn/primers/4.1) | ||
|
||
::: {.callout-note} | ||
### Pivoting | ||
|
||
Newer versions of **tidyr** have renamed these core functions: `gather()` is now `pivot_longer()` and `spread()` is now `pivot_wider()`. The syntax for these `pivot_*()` functions is *slightly* different from what it was in `gather()` and `spread()`, so you can't just replace the names. Fortunately, both `gather()` and `spread()` still work and won't go away for a while, so you can still use them as you learn about reshaping and tidying data. It would be worth learning how the newer `pivot_*()` functions work, eventually, though ([see here for examples](https://tidyr.tidyverse.org/articles/pivot.html)). | ||
::: |
Oops, something went wrong.