R Club 10.20.15

In today’s R Club session we’ll split the time between reviewing Basic R and a consultation.

In the Dropbox link below there are two sets of R Practice Code (called rclub1 and rclub2 and associated data files). The code typically has instructions and a function, but you’ll need to fill in the arguments. The plan is to give everyone some time to try it out on their own and then review and/or answer any questions. We’ll do either one or both of the sets (depending on how much time it takes) because we want to make sure to get to our first consultation of the year!

Here is what Rita would like help with:

She’d like to: a) pull zipcodes and scale scores from my excel data into R, b) match these zipcodes to a map of the US with state borders [I don’t care about zipcode borders], c) turn the scale + zipcode data into a heatmap of the country.

If you’re new to R Club, typically during a consultation we all try to work on the problem together and at the end of the session we’ll review what we figured out (or create a post about it if we run out of time). Rita’s example data are also in the Dropbox link below.

Dropbox Link:


Here are some sources that I’ve found to start thinking about how to create the sort of heat maps that Rita would like to create in R:



Edited to add another potentially helpful link:


One comment

  1. rosem@uoregon.edu

    if(!require(zipcode)) install.packages(“zipcode”); library(zipcode)
    df.raw <- read.csv("StudyFiveSampleOneWaveOne_forRclub.csv")
    if(!identical(x=clean.zipcodes(df.raw$ZipCode), y=as.character(df.raw$ZipCode)) ) message("Uh-oh") #check that zip codes in df are clean
    df <- df.raw
    df$zip <- clean.zipcodes(df$ZipCode)
    df <- na.omit(df)

    data(zipcode) # reads in a dataframe with the state for each zipcode
    df <- merge(df, zipcode[,c(1,3)], by="zip", all.x=T) # add a column of state abbreviations to the datafile

    df.state %
    group_by(state) %>%

    data(state.regions) # reads in a dataframe with the state name and state abbreviations

    df.state <- merge(df.state, state.regions[,c(1,2)], by.x="state", by.y="abb", all.x=T)

    map.data = data.frame(region=df.state$region, value=df.state$PScore)

Post a comment

You may use the following HTML:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>