Skip to content

Instantly share code, notes, and snippets.

@chris-prener
Last active October 18, 2017 14:52
Show Gist options
  • Save chris-prener/cc9eeccf29e437025049026f8faf9a88 to your computer and use it in GitHub Desktop.
Save chris-prener/cc9eeccf29e437025049026f8faf9a88 to your computer and use it in GitHub Desktop.
SOC 4930 & SOC 505 - Week 08 - Tips for Paired Data
# reprex of issues related to working with paired data
## dependencies
library(stlData)
library(dplyr)
library(ggplot2)
library(tidyr)
## data preparation
income <- stlIncome
income %>%
select(geoID, mi10_inflate, mi15) %>%
gather(key = year, value = medianInc, mi10_inflate, mi15) %>%
mutate(year = ifelse(year == "mi10_inflate", 2010, 2015)) %>%
arrange(geoID, year) -> incomeLong
incomeWide <- spread(incomeLong, key = year, value = medianInc)
## plot 1
ggplot() +
geom_boxplot(data = incomeLong, mapping = aes(x = year, y = medianInc))
## plot 2
ggplot() +
geom_boxplot(data = incomeLong, mapping = aes(x = year, y = medianInc, group = year))
## plot 3
ggplot() +
geom_boxplot(data = incomeLong, mapping = aes(x = as.factor(year), y = medianInc, group = year))
## using variables with numeric variable names
mean(incomeWide$`2010`)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment