For this activity, we’ll be examining the incidence of low birth weight around the state of Florida. Data are from Florida Charts (http://www.floridacharts.com), a site well worth checking out for lots of aggregated health data in our state.
Create a folder named lbw_tutorial and download the data into that folder. The specific dataset for this activity is at https://github.com/joebrew/misc/blob/master/lbw_tutorial/lbw.csv. If you’re familiar with github, you can clone the joebrew/misc directory entirely; if not, simply go to the previous link and download the data as a csv file (right click on the “Raw” button and save as a file).
In the lbw_tutorial directory, create an R script named lbw.R.
You’ll do this in two steps. First use
setwd()
to set your working directory, then use
read.csv()
to read in the data. Assign it to an object named lbw.
Ensure that numerical / character / categorical variables are as they should be. Do this using
str()
head()
tail()
summary()
If not, transform them using
as.character()
as.numeric()
as.factor()
First, use dplyr to arrange (sort) the data by percent poverty
library(dplyr)
lbw <-
lbw %>%
arrange(percent_poverty)
Make an ordered barplot of the percent_poverty variable using
barplot()
Use the names.arg, cex.names and las = 3 arguments in the barplot() function to print the county names vertically below the chart. If you want a challenge, color Alachua’s bar red and print a horizontal line at Alachua’s poverty rate.
Make a histogram of percent_poverty.
Re-arrange our data by population
lbw <- lbw %>%
arrange(total_pop)
Create variables named white_per, black_per and other_per. Also create lbw_per. These should be percent variables and should be easy to construct using simple divison and the total_pop vector and live_births vector.
plot(x, y)
If you want to get fancy, make the size (cex) a function of a county’s population size, as in the below plot
fit <- lm()
summary(fit)
plot(fit)
confint(fit)