Artwork by Allison Horst
Pre-class Prep
A. Install required packages
install.packages("usethis") # for editing .Renviron (see step C. in pre-class prep)
install.packages("chron") # for working with dates / times
install.packages("naniar") # tools for exploring & handing missing data
install.packages("tidytuesdayR") # used to download TidyTuesday data
install.packages("tidycensus") # an R package that allows users to interface with a select number of the US Census Bureau’s data APIs and return tidyverse-ready data frames
install.packages("ggridges") # {ggplot2} extension for creating ridgeline plots
install.packages("gghighlight") # {ggplot2} extension for highlighting geoms
install.packages("ggbeeswarm") # {ggplot2} extension for creating categorical scatter (violin point) plots
install.packages("see") # {ggplot2} extension for model visualization (we'll be using it for it's geom, geom_violindot())
install.packages("scales") # provides the internal scaling infrastructure used by ggplot2, and gives you tools to override the default breaks, labels, transformations and palettes (installed automatically with {ggplot2} or {tidyverse})
B. Download data
- Lyme Disease Cases by State or Locality (download link), made available by the CDC (read more on the CDC’s Lyme Disease Surveillance Data page; see other available data under the “Dashboard data files” section)
- save the downloaded data (
Lyme_Disease_Cases_by_State_or_Locality.csv
) to your class repo at the file path:EDS-240-class-examples/week2/data/Lyme_Disease_Cases_by_State_or_Locality.csv
- save the downloaded data (
C. Request a US Census Bureau API key & add it to your .Renviron
file
To use the
{tidycensus}
package to access US Census Bureau data, you’ll first need to request and activate an API key. Do so by following these steps:- Request an API key at http://api.census.gov/data/key_signup.html
- After a short period of time, you should receive an email with your key (it may be helpful to star / bookmark that email), and click the included link to activate your key (Note: if you get an error when activating your key, close your browser window and try clicking the activation link again).
Add your API key to your
.Renviron
file. For security purposes, you should NEVER push any API keys to GitHub. Rather than typing our API key into any of our scripts, we can instead save it to and read it from our.Renviron
file. Follow these steps:- Run
usethis::edit_r_environ()
in your Console, which will open up your.Renviron
file (it will create it if you don’t already have one). - Store envrionment variables as key / value pairs. Add your API key as shown, below, then save and restart R for your changes to take effect.
- Run
.Renviron
# be sure to name it exactly as written here (all caps)
="XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" CENSUS_API_KEY
- Note: You may also consider storing your API key in a password manager for safe keeping (e.g. in case your computer decides to call a quits, is lost, etc.)
.Renviron
?
Dotfiles (files which are preceded by a dot, .
) are hidden files, which are broadly used to customize the behavior of programs. You may already be familiar with some dotfiles, such as .gitconfig
and .gitignore
.
The .Renviron
file is an R-specific dotfile, which is commonly used for (though not limited to) storing sensitive information, such as API keys. It lives in your computer’s home directory (e.g. /Users/yourUserName
on macOS, or C:/Users/yourUserName/Documents
on Windows), and is automatically sourced when an R session starts. When sourced, all stored variables (such as your API key) are made available to your R environment for you to use. Variables should be stored as key / value pairs (e.g. KEY_NAME="VALUE"
. Access them using Sys.getenv("KEY_NAME")
.
Oftentimes, packages that are built to interface with APIs will include their own helper functions for adding API keys to your .Renviron
file (e.g. see tidycensus::census_api_key()
). You may choose to use these helper functions in place of usethis::edit_r_environ()
, if you prefer.
C. Download .qmd
templates & review initial data wrangling code
Download all necessary templates (links in the table below) and save them to a
EDS-240-data-viz-examples/week2/
folder.Review the data wrangling code under the
# Setup
section of each template file and make note of any questions you might have. Due to time constraints, we won’t be live-coding our way through the data wrangling code in class. However, we’ll reserve some time to answer any questions before we jump into data viz .
Lecture Materials
Lecture slides | Code-along template | Code-along key |
---|---|---|
Lecture 2.1: choosing graphic forms | NA | NA |
Lecture 2.2: visualizing distributions | 2.2 template | 2.2 key |
Lecture 2.3: visualizing evolution | 2.3 template | 2.3 key |
Pre-discussion Prep
A. Prepare a week2-discussion.qmd
file
Add a new blank file to your class repo at the following location: EDS-240-class-examples/week2/week2-discussion.qmd.
Fill out the necessary YAML information (title, author, date + any other information you find helpful).
B. (OPTIONAL) Install Google Chrome extension(s)
Install the ColorPick Eyedropper Google Chrome extension, which makes it easy to select color values from webpages.
Discussion Materials
Discussion Slides | Exercise instructions | Exercise solutions |
---|---|---|
D2 slides: USDM | D2 exercise: recreate USDM viz | D2 solution |
Assignment Reminders
Assignment Type | Assignment Title | Date Assigned | Date Due |
---|---|---|---|
EOC | EOC (week 2) | Mon 01/06/2025 | Mon 01/06/2025, 11:55pm PT |
HW | Homework Assignment #1 | Mon 01/06/2025 | Sat 01/18/2025, 11:59pm PT |