End Activity Session (Day 1)
1. Setup
Get the data and create a version-controlled R Project
2. Data import and exploration
Read in & explore the data
In your .qmd:
Attach the
tidyverse
andjanitor
packages in a new code chunkRead in the
stl_blood_lead.csv
data asstl_lead
and use janitor::clean_names to convert all variable names to lower snake caseDo some basic exploration of the dataset (e.g. using summary, data visualizations and summary statistics).
In a new code chunk, from
stl_blood_lead
create a new data frame calledstl_lead_prop
that has one additional column calledprop_white
that returns the percent of each census tract identifying as white (variablewhite
in the dataset divided by variabletotalPop
, times 100). You may need to do some Googling. Hint:dplyr::mutate(new_col = col_a / col_b)
will create a new columnnew_col
that contains the value ofcol_a / col_b
3. Visualize data
Create a scatterplot
- In a new code chunk, create a scatterplot graph of the percentage of children in each census tract with elevated blood lead levels (
pctElevated
) versus the percent of each census tract identifying as white. - Customize by updating several aesthetics (e.g. size, opacity (see
alpha =
), color, etc.) - Store the scatterplot as
stl_lead_plot
- Have the scatterplot returned in the knitted html - customize the size that it appears when knitted
- Also save a .png of the scatterplot to
figs
, with dimensions of (6” x 5”) (width x height) - In text above or below the scatterplot, write 1 - 2 sentences describing the overall trend that you observe from your graph
Create a histogram
- Create a histogram of only the
pctElevated
column in the data frame (remember, this will only take one variable - the frequency is calculated for you bygeom_histogram
) - Customize the fill, color, and size aesthetics - test some stuff! Feel free to make it awful.
- Once you’ve played around with customization, export the histogram as a .jpg to the
figs
folder - Make sure the histogram also shows up in your rendered html
4. Collaborate!
Render & push
- Render your .qmd
- Stage, commit, pull then push changes using the command line