These examples require tables that have been exported and aggregated for each year of the ACS.
## ACS 2022 Research Graphics
library(tidyverse)
path<-"~/Desktop/ACS/SAVED_TABLES/yearALL_tableDF"
tables<-c("0", "1", "2", "0R", "1R", "2R")
#### TABLES 0 and 0R
### IMPORT TABLES WITH PASTE (CHANGE TABLE INDEX)
tab0<-read.csv(paste(path, "0.csv", sep=""),
header=TRUE)
#head(tab0)
#View(tab0)
### LABELS FOR JOINING
modeLabs<-data.frame(RESMODE=c(1, 2, 3),
resmodeLab=c("1. Mail", "2. CATI/CAPI", "3. Internet"))
langLabs<-data.frame(HHL=c(1, 2, 3, 4, 5),
hhlLab=c("1. English", "2. Spanish", "3. Indo European", "4. Asian / Pacific Islander", "5. Other"),
jitter=c(-.2, -.1, 0, .1, .2))
lngiLab<-data.frame(LNGI=c(1, 2),
lngiLab=c("1. English Proficient",
"2. Limited English"))
#### GRAPHIC 1: QUESTION TYPE IN 2019
## NOTE: Confiddence interval calculated with bonferroni correction (conservative)
tab0%>%
filter(year==2019)%>%
ggplot(aes(x=closureT, y=mean, color=closureT))+
geom_point()+
geom_errorbar(aes(ymin=mean-qnorm(1-0.05/3)*SE, ymax=mean+qnorm(1-0.05/3)*SE), width=.2,
position=position_dodge(.9))
tab0%>%
filter(year==2019)%>%
ggplot(aes(x=closureT, y=mean, fill=closureT))+
geom_bar(stat="identity", color="black",
position=position_dodge())+
geom_errorbar(aes(ymin=mean-qnorm(1-0.05/3)*SE, ymax=mean+qnorm(1-0.05/3)*SE), width=.2,
position=position_dodge(.9))+
theme_bw()+
labs(title="2019 Allocation Rate by Type",
x="Question Type",
y = "Allocation Rate",
fill="Type")
## OVER YEARS
qtype<-data.frame(closureT=c("closed", "open", "partial"),
jitter1=c(-.2, 0, .2))
tab0%>%
left_join(qtype)%>%
mutate(jYear=year+jitter1)%>%
ggplot()+
geom_point(aes(x=year, y=mean, color=closureT))+
geom_line(aes(x=year, y=mean, color=closureT),lwd=1)+
geom_errorbar(aes(x=year,ymin=mean-qnorm(1-0.05/42)*SE, ymax=mean+qnorm(1-0.05/42)*SE), width=.2,
position=position_dodge(.9),
lwd=1)+
theme_bw()+
labs(title="Allocation Rate by Type",
x="Year",
y = "Allocation Rate",
color="Type")
#### by MODE
tab0R<-read.csv(paste(path, "0R.csv", sep=""),
header=TRUE)
head(tab0R)
## RESMODE rate se closureT year
## 1 1 0.015669264 6.064758e-05 closed 2006
## 2 2 0.030654974 1.075259e-04 closed 2006
## 3 1 0.008778373 8.663009e-05 open 2006
## 4 2 0.023784792 1.890786e-04 open 2006
## 5 1 0.055198979 1.190920e-04 partial 2006
## 6 2 0.066135296 2.218384e-04 partial 2006
dim(tab0R)
## [1] 105 5
tab0R%>%
left_join(qtype)%>%
left_join(modeLabs)%>%
mutate(jYear=year+jitter1)%>%
ggplot()+
#geom_point(aes(x=year, y=rate, color=closureT))+
geom_line(aes(x=year, y=rate, color=closureT))+
geom_errorbar(aes(x=year,ymin=rate-qnorm(1-0.05/105)*se, ymax=rate+qnorm(1-0.05/105)*se), width=.2,
position=position_dodge(.9))+
theme_bw()+
facet_grid(.~resmodeLab)+
labs(title="Allocation Rate by Type and Mode",
x="Year",
y = "Allocation Rate",
fill="Type")