Skip to content

Instantly share code, notes, and snippets.

@dbetebenner
Created August 17, 2021 15:52
Show Gist options
  • Save dbetebenner/feb541f71b850580e28a00978600f282 to your computer and use it in GitHub Desktop.
Save dbetebenner/feb541f71b850580e28a00978600f282 to your computer and use it in GitHub Desktop.
Arizona academic impact bubblePlot code
################################################################################
### ###
### Arizona -- Investigation of Pandemic Academic Impact by School ###
### ###
################################################################################
### Load packages
require(SGP)
require(cfaTools)
### Load data
#load("/Users/conet/Github/CenterForAssessment/Arizona/master/Data/Arizona_SGP_with_2016_to_2018_SGPs.Rdata")
load("Data/School_Summaries_List.Rdata")
### Create and save school summaries for bubblePlot
#School_Summaries_List <- academicImpactSummary(Arizona_SGP, state='AZ', current_year='2021', prior_year='2019', content_areas=c('ELA', 'MATHEMATICS'), grades=as.character(c(3:8, 10)))
#save(School_Summaries_List, file="Data/School_Summaries_List.Rdata")
### Convert Academic Impact Variables to ordered factors.
for (impact.iter in grep("COVID_ACADEMIC_IMPACT", names(School_Summaries_List$SCHOOL_SUMMARIES), value=TRUE)) {
School_Summaries_List[['SCHOOL_SUMMARIES']][,eval(impact.iter):=factor(eval(parse(text=impact.iter)), levels=c("Improvement", "Modest to None", "Moderate", "Large", "Severe"), ordered=TRUE)]
}
### Loop over YEAR
for (year.iter in c("2019", "2021")) {
current.year <- year.iter
prior.year <- as.character(as.numeric(current.year)-2)
### Loop over ACADEMIC_IMPACT
impact.measures <- c("COVID_ACADEMIC_IMPACT_SGP_DIFF", "COVID_ACADEMIC_IMPACT_SGP_DIFF_ADJ",
"COVID_ACADEMIC_IMPACT_GES_MEDIAN_SGP", "COVID_ACADEMIC_IMPACT_GES_MEDIAN_SGP_ADJ")
for (impact.measure.iter in impact.measures) {
impact.measure.scale <- ifelse(grepl("SGP_DIFF", impact.measure.iter), 1, 2)
impact.measure.scale <- list(c("Improvement (> 5)", "Modest to None (-5 to 5)", "Moderate (-15 to -5)", "Large (-25 to -15)", "Severe (< -25)"),
c("Improvement (> 0.2)", "Modest to None (-0.2 to 0.2)", "Moderate (-0.2 to -0.5)", "Large (-0.5 to -0.8)", "Severe (< -0.8)"))[[impact.measure.scale]]
for (content_area.iter in c("ELA", "MATHEMATICS")) {
tmp.school.data.wide <- School_Summaries_List[['SCHOOL_SUMMARIES']][CONTENT_AREA==content_area.iter & COUNT_SGP >= 20 & YEAR==year.iter & !is.na(get(impact.measure.iter))]
for (covid.iter in tmp.levels <- c("Improvement", "Modest to None", "Moderate", "Large", "Severe")) {
### message
tmp.color <- rev(colorspace::rainbow_hcl(length(tmp.levels)))[which(covid.iter==tmp.levels)]
tmp.percentage <- round(100*sum(tmp.school.data.wide[[impact.measure.iter]]==covid.iter)/length(tmp.school.data.wide[[impact.measure.iter]]==covid.iter), digits=1)
tmp.lgla.percentage <- round(100*sum(tmp.school.data.wide[MEDIAN_SGP_PRIOR_2YEAR < 50 & PERCENT_PROFICIENT_PRIOR < 50][[impact.measure.iter]]==covid.iter)/
length(tmp.school.data.wide[MEDIAN_SGP_PRIOR_2YEAR < 50 & PERCENT_PROFICIENT_PRIOR < 50][[impact.measure.iter]]==covid.iter), digits=1)
tmp.hgla.percentage <- round(100*sum(tmp.school.data.wide[MEDIAN_SGP_PRIOR_2YEAR >= 50 & PERCENT_PROFICIENT_PRIOR < 50][[impact.measure.iter]]==covid.iter)/
length(tmp.school.data.wide[MEDIAN_SGP_PRIOR_2YEAR >= 50 & PERCENT_PROFICIENT_PRIOR < 50][[impact.measure.iter]]==covid.iter), digits=1)
tmp.hgha.percentage <- round(100*sum(tmp.school.data.wide[MEDIAN_SGP_PRIOR_2YEAR >= 50 & PERCENT_PROFICIENT_PRIOR >= 50][[impact.measure.iter]]==covid.iter)/
length(tmp.school.data.wide[MEDIAN_SGP_PRIOR_2YEAR >= 50 & PERCENT_PROFICIENT_PRIOR >= 50][[impact.measure.iter]]==covid.iter), digits=1)
tmp.lgha.percentage <- round(100*sum(tmp.school.data.wide[MEDIAN_SGP_PRIOR_2YEAR < 50 & PERCENT_PROFICIENT_PRIOR >= 50][[impact.measure.iter]]==covid.iter)/
length(tmp.school.data.wide[MEDIAN_SGP_PRIOR_2YEAR < 50 & PERCENT_PROFICIENT_PRIOR >= 50][[impact.measure.iter]]==covid.iter), digits=1)
bPlot.message <- c("grid.lines(x=unit(50, 'native'), y=c(0.03,0.97), gp=gpar(col='grey40', lwd=1.25, lty=2, alpha=0.5))",
paste0("grid.text('", paste0(tmp.percentage, '%'), "', x=unit(50, 'native'), y=unit(90, 'native'), gp=gpar(cex=4.0, col='", tmp.color, "'), just='center')"),
paste0("grid.text('", paste0(tmp.lgla.percentage, '%'), "', x=unit(10, 'native'), y=unit(20, 'native'), gp=gpar(cex=2.0, col='", tmp.color, "'), just='left')"),
paste0("grid.text('", paste0(tmp.hgla.percentage, '%'), "', x=unit(90, 'native'), y=unit(20, 'native'), gp=gpar(cex=2.0, col='", tmp.color, "'), just='right')"),
paste0("grid.text('", paste0(tmp.hgha.percentage, '%'), "', x=unit(90, 'native'), y=unit(80, 'native'), gp=gpar(cex=2.0, col='", tmp.color, "'), just='right')"),
paste0("grid.text('", paste0(tmp.lgha.percentage, '%'), "', x=unit(10, 'native'), y=unit(80, 'native'), gp=gpar(cex=2.0, col='", tmp.color, "'), just='left')")
)
bubblePlot(
bubble_plot_data.X=tmp.school.data.wide[["MEDIAN_SGP_BASELINE_PRIOR"]],
bubble_plot_data.Y=tmp.school.data.wide[["PERCENT_PROFICIENT_PRIOR"]],
bubble_plot_data.SUBSET=which(tmp.school.data.wide[[impact.measure.iter]]==covid.iter),
bubble_plot_data.INDICATE=NULL,
bubble_plot_data.BUBBLE_CENTER_LABEL=NULL,
bubble_plot_data.SIZE=tmp.school.data.wide[["COUNT_SGP"]],
bubble_plot_data.LEVELS=tmp.school.data.wide[[impact.measure.iter]],
bubble_plot_labels.X=c("Growth", paste(prior.year, "Median Student Growth Percentile")),
bubble_plot_labels.Y=c("Achievement", paste(prior.year, "Percent Proficient")),
bubble_plot_labels.SIZE=c(50, 100, 250, 500),
bubble_plot_labels.LEVELS=impact.measure.scale,
bubble_plot_titles.MAIN=paste0("AzM2: ", capwords(content_area.iter)),
bubble_plot_titles.SUB1="School Level COVID Academic Impact",
bubble_plot_titles.SUB2=paste(prior.year, "Growth by Achievement"),
bubble_plot_titles.LEGEND1="School Size",
bubble_plot_titles.LEGEND2_P1="COVID Impact",
bubble_plot_titles.LEGEND2_P2=paste(current.year, "SGP -", prior.year, "SGP"),
bubble_plot_configs.BUBBLE_MIN_MAX=c(0.04, 0.11),
bubble_plot_configs.BUBBLE_X_TICKS=seq(0,100,10),
bubble_plot_configs.BUBBLE_X_TICKS_SIZE=c(rep(0.6, 5), 0.8, rep(0.6, 5)),
bubble_plot_configs.BUBBLE_Y_TICKS=seq(0,100,10),
bubble_plot_configs.BUBBLE_Y_TICKS_SIZE=rep(0.6, 11),
bubble_plot_configs.BUBBLE_PLOT_BACKGROUND_LABELS=c("Growth", "Achievement"),
bubble_plot_configs.BUBBLE_SUBSET_INCREASE=0.00,
bubble_plot_configs.BUBBLE_COLOR=NULL,
bubble_plot_configs.BUBBLE_SUBSET_ALPHA=list(Transparent=0.3, Opaque=0.9),
bubble_plot_configs.BUBBLE_PLOT_DEVICE="PDF",
bubble_plot_configs.BUBBLE_PLOT_FORMAT="print",#"presentation",
bubble_plot_configs.BUBBLE_PLOT_LEGEND="TRUE",
bubble_plot_configs.BUBBLE_PLOT_TITLE="TRUE",
bubble_plot_configs.BUBBLE_PLOT_SUMMARY_STATISTICS=FALSE,
bubble_plot_configs.BUBBLE_PLOT_EXTRAS=bPlot.message,
bubble_plot_configs.BUBBLE_PLOT_NAME=paste(paste("AzM2", capwords(content_area.iter), "Academic_Impact_by_School", covid.iter, sep="_"), ".pdf", sep=""),
bubble_plot_configs.BUBBLE_PLOT_PATH=file.path("assets", "Rplots", "bubblePlots", "AzM2", impact.measure.iter),
bubble_plot_pdftk.CREATE_CATALOG=FALSE)
} ### END covid.iter
} ### END content_area.iter
} ### END impact.measure.iter
} ### END year.iter
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment