Tuesday, August 4, 2015

Code to analyze racial composition in Washington Jails.



Political piece for this code is here. There are two separate R files below.

# Code to mux WASPC (WA Sherrif) Jail Data with County Census Demographics
# Code to examine population disproportionate incarceration patterns
# 7:34 PM Thursday, July 23, 2015 -RMF

# Sources
# http://www.census.gov/popest/data/counties/asrh/2014/CC-EST2014-ALLDATA.html
# http://www.waspc.org/assets/CJIS/2014%20jail%20statistics_website.xlsx
# http://www.waspc.org/crime-statistics-reports
cat('as.matrix(names(J2014))
      [,1]         
 [1,] "Jail"       
 [2,] "Capacity"   
 [3,] "AveDBR"     
 [4,] "AveDailyPop"
 [5,] "PCT_USE"    
 [6,] "AveLOS"     
 [7,] "Males"      
 [8,] "Females"    
 [9,] "UnGender"   
[10,] "White"      
[11,] "Black"      
[12,] "Hispanic"   
[13,] "NatAmerican"
[14,] "Other"      
[15,] "UnRace"
')
library(dplyr)
library(lattice)

setwd("C:/JoyGilfilen")
# From http://www.waspc.org/crime-statistics-reports
#J2014 <- read.csv("2014jail.csv",stringsAsFactors = FALSE)
#J2013 <- read.csv("2013jail.csv",stringsAsFactors = FALSE)
#J2012 <- read.csv("2012jail.csv",stringsAsFactors = FALSE)
#J2011 <- read.csv("2011jail.csv",stringsAsFactors = FALSE)
#J2010 <- read.csv("2010jail.csv",stringsAsFactors = FALSE)

J2014 <- read.csv("2014jail.csv",stringsAsFactors = FALSE); J2014 <- data.frame(cbind(J2014,"Year"=2014,stringsAsFactors = FALSE))
J2013 <- read.csv("2013jail.csv",stringsAsFactors = FALSE); J2013 <- data.frame(cbind(J2013,"Year"=2013,stringsAsFactors = FALSE))
J2012 <- read.csv("2012jail.csv",stringsAsFactors = FALSE); J2012 <- data.frame(cbind(J2012,"Year"=2012,stringsAsFactors = FALSE))
J2011 <- read.csv("2011jail.csv",stringsAsFactors = FALSE); J2011 <- data.frame(cbind(J2011,"Year"=2011,stringsAsFactors = FALSE))
J2010 <- read.csv("2010jail.csv",stringsAsFactors = FALSE); J2010 <- data.frame(cbind(J2010,"Year"=2010,stringsAsFactors = FALSE))
J.10.14 <- data.frame(rbind(J2014,J2013,J2012,J2011,J2010),stringsAsFactors = FALSE)
J.10.14.POC <- data.frame(cbind(J.10.14,"POC" =with(J.10.14,apply(cbind(Black,Hispanic,NatAmerican,Other),1,sum,na.rm = TRUE))))


quantile(J2014$Capacity, probs = seq(0, 1, 0.1), na.rm = TRUE)

attach(J2014)
# Set up pct and nom datasets for attached data
pct <- data.frame(Jail,Males/AveDailyPop, Females/AveDailyPop,
Black/AveDailyPop, Hispanic/AveDailyPop, NatAmerican/AveDailyPop, Other/AveDailyPop, White/AveDailyPop,UnRace/AveDailyPop,
"POC/AveDailyPop" =(Black + Hispanic + NatAmerican + Other) / AveDailyPop,
stringsAsFactors = FALSE)

nom <- data.frame(Jail,Capacity,AveDBR,AveDailyPop,PCT_USE,AveLOS,
Males, Females,
White,Black, Hispanic, NatAmerican, Other,UnRace,
"POC" =(Black + Hispanic + NatAmerican + Other),
stringsAsFactors = FALSE)

s1 <- arrange(pct,desc(POC.AveDailyPop))[,c(1,10)]
s1 <- with(s1,data.frame("CTYNAME" = Jail,"NotWhiteAlone" = POC.AveDailyPop,stringsAsFactors = FALSE))
s1n <- arrange(nom,desc(POC))[,c(1,4,15)]
s1n <- with(s1n,data.frame("CTYNAME" = Jail,"NotWhiteAlone" = POC,stringsAsFactors = FALSE))

# Census population data for Counties 2010 - 2014 
# More information see: 
# http://www.census.gov/popest/data/counties/asrh/2014/files/CC-EST2014-ALLDATA.pdf
# http://www.census.gov/popest/index.html

# The key for the YEAR variable is as follows:
# 1 = 4/1/2010 Census population
# 2 = 4/1/2010 population estimates base
# 3 = 7/1/2010 population estimate
# 4 = 7/1/2011 population estimate
# 5 = 7/1/2012 population estimate
# 6 = 7/1/2013 population estimate
# 7 = 7/1/2014 population estimate

# Get County Census data for WA
# download.file("http://www.census.gov/popest/data/counties/asrh/2014/files/CC-EST2014-ALLDATA-53.csv","CC-EST2014-ALLDATA-53.csv")
EST2014 <- read.csv("CC-EST2014-ALLDATA-53.csv",stringsAsFactors = FALSE)
EST2014 <- subset(EST2014, YEAR == 7 & AGEGRP == 0)
EST2014WApct <- with(EST2014,arrange(data.frame(CTYNAME, "WhiteAlone" = ((WA_MALE + WA_FEMALE) / TOT_POP)),desc(WhiteAlone)))
EST2014WAnom <- with(EST2014,arrange(data.frame(CTYNAME, "TotalPop"=TOT_POP, "WhiteAlone" = WA_MALE + WA_FEMALE),desc(WhiteAlone)))
EST2014WApct$CTYNAME <- gsub("County","",EST2014WApct$CTYNAME)
EST2014WAnom$CTYNAME <- gsub("County","",EST2014WAnom$CTYNAME)
s2 <- EST2014WApct
s2n <- EST2014WAnom

# Merge Census and WASPC data
s1$CTYNAME <- gsub(" ","",s1$CTYNAME)
s2$CTYNAME <- gsub(" ","",s2$CTYNAME)
s3 <- merge(s1,s2,all=TRUE,stringsAsFactors = FALSE)
s3 <- arrange(data.frame(s3, "k"=(s3$NotWhiteAlone - (1 - s3$WhiteAlone))),k)
s4 <- with(s3,data.frame("County.City"=CTYNAME,"PCTNotWhiteInJail"=scales::percent(NotWhiteAlone),"PCTWhiteInPop"=scales::percent(WhiteAlone),
"K"=scales::percent(NotWhiteAlone - (1 - WhiteAlone))))
s4

s1n$CTYNAME <- gsub(" ","",s1n$CTYNAME)
s2n$CTYNAME <- gsub(" ","",s2n$CTYNAME)
s3n <- merge(s1n,s2n,all=TRUE,stringsAsFactors = FALSE)
s4n <- with(s3n,data.frame(
"County.City"=CTYNAME,
"TotalPop"=TotalPop,
"AverageDailyJail"=AveDailyPop,
"NotWhiteAloneInJail"=NotWhiteAlone,
"AllWhiteInPop"=WhiteAlone))
s4n <- arrange(s4n,desc(AllWhiteInPop))
s4n

# Statewide disproportionate pct and nom
t1 <- with(s4n[,c(1,3,4)],sum(NotWhiteAloneInJail,na.rm=TRUE)/sum(AverageDailyJail,na.rm=TRUE))
t2 <- with(s4n[,c(1,2,5)],sum(AllWhiteInPop,na.rm=TRUE)/sum(TotalPop,na.rm=TRUE))
t1 - (1 - t2)
# work needed here
t3 <- with(s4n[,c(1,3,4)],sum(AverageDailyJail,na.rm=TRUE) - sum(NotWhiteAloneInJail,na.rm=TRUE) )
t4 <- with(s4n[,c(1,2,5)],sum(TotalPop,na.rm=TRUE) - sum(AllWhiteInPop,na.rm=TRUE))


# Per race per county disproportionate
# Categories (vectored) division; Males.AveDailyPop == Males/AveDailyPop
cat('
 as.matrix(names(pct_GTR_250))
      [,1]                     
 [1,] "Jail"                   
 [2,] "Males.AveDailyPop"      
 [3,] "Females.AveDailyPop"    
 [4,] "Black.AveDailyPop"      
 [5,] "Hispanic.AveDailyPop"   
 [6,] "NatAmerican.AveDailyPop"
 [7,] "Other.AveDailyPop"      
 [8,] "White.AveDailyPop"      
 [9,] "UnRace.AveDailyPop"     
[10,] "POC.AveDailyPop" # POC == People of Color == Not White or Not White Alone (??)
')

J2014_GTR_150 <-  subset(J2014, Capacity > 150)
pct_GTR_150 <- subset(pct, Jail %in% J2014_GTR_150$Jail)
nom_GTR_150 <- subset(nom, Jail %in% J2014_GTR_150$Jail)

J2014_GTR_250 <-  subset(J2014, Capacity > 250)
pct_GTR_250 <- subset(pct, Jail %in% J2014_GTR_250$Jail)
nom_GTR_250 <- subset(nom, Jail %in% J2014_GTR_250$Jail)

J2014_GTR_500 <-  subset(J2014, Capacity > 500)
pct_GTR_500 <- subset(pct, Jail %in% J2014_GTR_500$Jail)
nom_GTR_500 <- subset(nom, Jail %in% J2014_GTR_500$Jail)

detach(J2014)
      
# Every Jail > 250 gives Native American pct
attach(pct_GTR_250)

n250 <- arrange(pct_GTR_250[,c(1,6)],desc(NatAmerican.AveDailyPop))
with(n250,data.frame(Jail,PCT_NA = scales::percent(NatAmerican.AveDailyPop)))

# Whatcom County Jail  > 250 gives Native American pct
n250 <- arrange(pct_GTR_250[which(Jail == "Whatcom"),c(1,6)],desc(NatAmerican.AveDailyPop))
with(n250,data.frame(Jail,PCT_NA = scales::percent(NatAmerican.AveDailyPop)))

# All Jail > 250 gives All RACE disproportionate percentage
z1 <- pct_GTR_250[,c(1,4:10)]
cbind(z1[1],sapply(z1[,c(2:8)],scales::percent))

z1 <- nom_GTR_250[,c(1,4:10)]
cbind(z1[,c(1,2:8)])

detach(pct_GTR_250)

#.... Charts
# Whatcom County By Year
wR1 <- subset(J.10.14, Jail == "Whatcom",select=c("Jail","Year","White","Black","Hispanic","NatAmerican","Other","UnRace"))
wR1
attach(wR1)
# White
par(mfrow=c(1,2))
plot(White ~ Year, type="b",col="beige",lwd=5,ylab="White + People of Color",ylim=c(0,304));
lines(Black ~ Year, type="b",col="black",lwd=5,ylim=c(0,304));
lines(Hispanic ~ Year, type="b",col="brown",lwd=5,ylim=c(0,304));
lines(NatAmerican ~ Year, type="b",col="orange",lwd=8,ylim=c(0,304));
lines(Other ~ Year, type="b",col="yellow",lwd=5,ylim=c(0,304));
lines(UnRace ~ Year, type="b",col="grey",lwd=5,ylim=c(0,304));

# POC
plot(Black ~ Year, type="b",col="black",lwd=5,ylab="People of Color",ylim=c(0,100));
lines(Hispanic ~ Year, type="b",col="brown",lwd=5,ylim=c(0,100));
lines(NatAmerican ~ Year, type="b",col="orange",lwd=8,ylim=c(0,100));
lines(Other ~ Year, type="b",col="yellow",lwd=5,ylim=c(0,100));
lines(UnRace ~ Year, type="b",col="grey",lwd=5,ylim=c(0,100));
par(mfrow=c(1,1))
mtext("Average Daily Beds for Whatcom County Jail by Race 2010 - 2014:",line=2, side=3)
mtext("White (beige),Black (black), Hispanic (brown), Native American (orange), Other + Asian (yellow), Unknown (grey)",line=1, side=3)
detach(wR1)

# All State by Year
WAR1 <- subset(J.10.14, select=c("Jail","Year","White","Black","Hispanic","NatAmerican","Other","UnRace"))
# WAR2014 <- subset(WAR1, Year == 2014,select=c("Year","White","Black","Hispanic","NatAmerican","Other","UnRace"))
# WAR2014 <- cbind(Year=2014,rbind(colSums(WAR1[c(-1)],na.rm=TRUE)))

WAR1 <- data.frame(rbind(
cbind(Year=2014,rbind(colSums(filter(WAR1,Year==2014)[c(-1,-2)],na.rm=TRUE))),
cbind(Year=2013,rbind(colSums(filter(WAR1,Year==2013)[c(-1,-2)],na.rm=TRUE))),
cbind(Year=2012,rbind(colSums(filter(WAR1,Year==2012)[c(-1,-2)],na.rm=TRUE))),
cbind(Year=2011,rbind(colSums(filter(WAR1,Year==2011)[c(-1,-2)],na.rm=TRUE))),
cbind(Year=2010,rbind(colSums(filter(WAR1,Year==2010)[c(-1,-2)],na.rm=TRUE)))
))
WAR1
wmax <- max(WAR1$White)
bmax <- max(WAR1$Black)

attach(WAR1)
# White + POC
par(mfrow=c(1,2))
plot(White ~ as.factor(Year), type="b",col="beige",lwd=4,ylab="White + People of Color",ylim=c(0,wmax));
lines(Black ~ Year, type="b",col="black",lwd=4,ylim=c(0,wmax));
lines(Hispanic ~ Year, type="b",col="brown",lwd=4,ylim=c(0,wmax));
lines(NatAmerican ~ Year, type="b",col="orange",lwd=4,ylim=c(0,wmax));
lines(Other ~ Year, type="b",col="yellow",lwd=4,ylim=c(0,wmax));
lines(UnRace ~ Year, type="b",col="grey",lwd=4,ylim=c(0,wmax));

# POC
plot(Black ~ Year, type="b",col="black",lwd=4,ylab="People of Color",ylim=c(0,bmax));
lines(Hispanic ~ Year, type="b",col="brown",lwd=4,ylim=c(0,bmax));
lines(NatAmerican ~ Year, type="b",col="orange",lwd=4,ylim=c(0,bmax));
lines(Other ~ Year, type="b",col="yellow",lwd=4,ylim=c(0,bmax));
lines(UnRace ~ Year, type="b",col="grey",lwd=4,ylim=c(0,bmax));
par(mfrow=c(1,1))
mtext("Average Daily Beds for WA StateJail by Race 2010 - 2014:",line=2, side=3)
mtext("White (beige),Black (black), Hispanic (brown), Native American (orange), Other + Asian (yellow), Unknown (grey)",line=1, side=3)
detach(WAR1)

#pie charts ...only so useful
attach(J2014)
with(arrange(subset(pct,Hispanic.AveDailyPop != "NA",select=c(Jail,Hispanic.AveDailyPop)),desc(Hispanic.AveDailyPop)),
pie(Hispanic.AveDailyPop,labels=Jail,col=rainbow(8),radius = 1,cex=.75))
mtext("Hispanic / Ave Daily Pop for select WA Jails")
with(arrange(subset(pct,NatAmerican.AveDailyPop != "NA",select=c(Jail,NatAmerican.AveDailyPop)),desc(NatAmerican.AveDailyPop)),
pie(NatAmerican.AveDailyPop,labels=Jail,col=rainbow(8),radius = 1,cex=.75))
mtext("Native American / Ave Daily Pop for select WA Jails")
with(arrange(subset(pct,Black.AveDailyPop != "NA",select=c(Jail,Black.AveDailyPop)),desc(Black.AveDailyPop)),
pie(Black.AveDailyPop,labels=Jail,col=rainbow(8),radius = 1,cex=.75))
mtext("Black / Ave Daily Pop for select WA Jails")
with(arrange(subset(pct,Other.AveDailyPop != "NA",select=c(Jail,Other.AveDailyPop)),desc(Other.AveDailyPop)),
pie(Other.AveDailyPop,labels=Jail,col=rainbow(8),radius = 1,cex=.75))
mtext("Other including Asian / Ave Daily Pop for select WA Jails")
with(arrange(subset(pct,White.AveDailyPop != "NA",select=c(Jail,White.AveDailyPop)),desc(White.AveDailyPop)),
pie(White.AveDailyPop,labels=Jail,col=rainbow(8),radius = 1,cex=.75))
mtext("White / Ave Daily Pop for select WA Jails")
with(arrange(subset(pct,POC.AveDailyPop != "NA",select=c(Jail,POC.AveDailyPop)),desc(POC.AveDailyPop)),
pie(POC.AveDailyPop,labels=Jail,col=rainbow(8),radius = 1,cex=.75))
mtext("People of Color / Ave Daily Pop for select WA Jails")

pctl <- pct_GTR_150
with(arrange(subset(pctl,Hispanic.AveDailyPop != "NA",select=c(Jail,Hispanic.AveDailyPop)),desc(Hispanic.AveDailyPop)),
pie(Hispanic.AveDailyPop,labels=Jail,col=rainbow(8),radius = 1,cex=.75))
mtext("Hispanic / Ave Daily Pop for WA Jails with Capacity > 150")
with(arrange(subset(pctl,NatAmerican.AveDailyPop != "NA",select=c(Jail,NatAmerican.AveDailyPop)),desc(NatAmerican.AveDailyPop)),
pie(NatAmerican.AveDailyPop,labels=Jail,col=rainbow(8),radius = 1,cex=.75))
mtext("Native American / Ave Daily Pop for WA Jails with Capacity > 150")
with(arrange(subset(pctl,Black.AveDailyPop != "NA",select=c(Jail,Black.AveDailyPop)),desc(Black.AveDailyPop)),
pie(Black.AveDailyPop,labels=Jail,col=rainbow(8),radius = 1,cex=.75))
mtext("Black / Ave Daily Pop for WA Jails with Capacity > 150")
with(arrange(subset(pctl,Other.AveDailyPop != "NA",select=c(Jail,Other.AveDailyPop)),desc(Other.AveDailyPop)),
pie(Other.AveDailyPop,labels=Jail,col=rainbow(8),radius = 1,cex=.75))
mtext("Other including Asian / Ave Daily Pop for WA Jails with Capacity > 150")
with(arrange(subset(pctl,White.AveDailyPop != "NA",select=c(Jail,White.AveDailyPop)),desc(White.AveDailyPop)),
pie(White.AveDailyPop,labels=Jail,col=rainbow(8),radius = 1,cex=.75))
mtext("White / Ave Daily Pop for WA Jails with Capacity > 150")
with(arrange(subset(pctl,POC.AveDailyPop != "NA",select=c(Jail,POC.AveDailyPop)),desc(POC.AveDailyPop)),
pie(POC.AveDailyPop,labels=Jail,col=rainbow(8),radius = 1,cex=.75))
mtext("People of Color / Ave Daily Pop for select WA Jails")

detach(J2014)

# Sources
# http://www.census.gov/popest/data/counties/asrh/2014/CC-EST2014-ALLDATA.html
# http://www.waspc.org/assets/CJIS/2014%20jail%20statistics_website.xlsx


# Code to chart WASPC (WA Sherrif) Jail Data 
# Code to examine population disproportionate incarceration patterns
# 8:33 PM Tuesday, July 28, 2015 -RMF

# Sources
# http://www.census.gov/popest/data/counties/asrh/2014/CC-EST2014-ALLDATA.html
# http://www.waspc.org/assets/CJIS/2014%20jail%20statistics_website.xlsx
# http://www.waspc.org/crime-statistics-reports

library(lattice)
library(dplyr)
library(sqldf)
setwd("C:/JoyGilfilen")
# From http://www.waspc.org/crime-statistics-reports
J2014 <- read.csv("2014jail.csv",stringsAsFactors = FALSE); J2014 <- data.frame(cbind(J2014,"Year"=2014,stringsAsFactors = FALSE))
J2013 <- read.csv("2013jail.csv",stringsAsFactors = FALSE); J2013 <- data.frame(cbind(J2013,"Year"=2013,stringsAsFactors = FALSE))
J2012 <- read.csv("2012jail.csv",stringsAsFactors = FALSE); J2012 <- data.frame(cbind(J2012,"Year"=2012,stringsAsFactors = FALSE))
J2011 <- read.csv("2011jail.csv",stringsAsFactors = FALSE); J2011 <- data.frame(cbind(J2011,"Year"=2011,stringsAsFactors = FALSE))
J2010 <- read.csv("2010jail.csv",stringsAsFactors = FALSE); J2010 <- data.frame(cbind(J2010,"Year"=2010,stringsAsFactors = FALSE))
J.10.14 <- data.frame(rbind(J2014,J2013,J2012,J2011,J2010),stringsAsFactors = FALSE)
J.10.14.POC <- data.frame(cbind(J.10.14,"POC" =with(J.10.14,apply(cbind(Black,Hispanic,NatAmerican,Other),1,sum,na.rm = TRUE))))

wR1 <- subset(J.10.14.POC, Jail == "Whatcom",select=c("Jail","Year","White","Black","Hispanic","NatAmerican","Other","UnRace","POC"))
WAR1 <- subset(J.10.14.POC, select=c("Jail","Year","White","Black","Hispanic","NatAmerican","Other","UnRace","POC"))
WAR1 <- data.frame(rbind(
cbind(Year=2014,rbind(colSums(filter(WAR1,Year==2014)[c(-1,-2)],na.rm=TRUE))),
cbind(Year=2013,rbind(colSums(filter(WAR1,Year==2013)[c(-1,-2)],na.rm=TRUE))),
cbind(Year=2012,rbind(colSums(filter(WAR1,Year==2012)[c(-1,-2)],na.rm=TRUE))),
cbind(Year=2011,rbind(colSums(filter(WAR1,Year==2011)[c(-1,-2)],na.rm=TRUE))),
cbind(Year=2010,rbind(colSums(filter(WAR1,Year==2010)[c(-1,-2)],na.rm=TRUE)))
))

wR1
WAR1

aggr_dfWAR1 <- data.frame(aggregate(cbind(White,Black,Hispanic,NatAmerican,Other,UnRace) ~ Year,data=WAR1,sum))
barchart(as.factor(Year) ~ White + Black + Hispanic + NatAmerican + Other + UnRace,xlab="",origin=0,data=aggr_dfWAR1,allow.multiple=TRUE,
auto.key = list(space='right',cex=1.2,text=c('White','Black','Hispanic','Native American','Other includes Asian','Unidentified Race')))
title(main = "Sum of all Average Daily Pop for All WA Jails across all Races WA 2010 - 2014")

aggr_dfWAR2 <- data.frame(aggregate(cbind(Black,Hispanic,NatAmerican,Other,UnRace) ~ Year,data=WAR1,sum))
barchart(as.factor(Year) ~ Black + Hispanic + NatAmerican + Other + UnRace,xlab="",origin=0,data=aggr_dfWAR2,allow.multiple=TRUE,
auto.key =list(space='right',cex=1.2,text=c('Black','Hispanic','Native American','Other includes Asian','Unidentified Race')))
title(main = "Sum of Average Daily Pop for All WA Jails across those not white or unknown: WA 2010 - 2014")

aggr_dfWAR3 <- data.frame(aggregate(cbind(White,POC) ~ Year,origin=0,data=WAR1,sum))
barchart(as.factor(Year) ~ White + POC,xlab="", data=aggr_dfWAR3,allow.multiple=TRUE,
auto.key =list(space='right',cex=1.2,text=c('White','People of Color')))
title(main = "Average Daily Bed Pop for All WA Jails for White and POC (People of Color): 2011 - 2014")

aggr_dfwR1 <- data.frame(aggregate(cbind(White,Black,Hispanic,NatAmerican,Other,UnRace) ~ Year,origin=0,data=wR1,sum))
barchart(as.factor(Year) ~ White + Black + Hispanic + NatAmerican + Other + UnRace,xlab="", data=aggr_dfwR1,allow.multiple=TRUE,
auto.key = list(space='right',cex=1.2,text=c('White','Black','Hispanic','Native American','Other includes Asian','Unidentified Race')))
title(main = "Average Daily Pop Whatcom County across all Races WA 2010 - 2014")

aggr_dfwR2 <- data.frame(aggregate(cbind(Black,Hispanic,NatAmerican,Other,UnRace) ~ Year,origin=0,data=wR1,sum))
barchart(as.factor(Year) ~ Black + Hispanic + NatAmerican + Other + UnRace,xlab="", data=aggr_dfwR2,allow.multiple=TRUE,
auto.key =list(space='right',cex=1.2,text=c('Black','Hispanic','Native American','Other includes Asian','Unidentified Race')))
title(main = "Average Daily Pop for Whatcom County across those not white or unknown: 2010 - 2014")

aggr_dfwR3 <- data.frame(aggregate(cbind(White,POC) ~ Year,origin=0,data=wR1,sum))
barchart(as.factor(Year) ~ White + POC,xlab="", data=aggr_dfwR3,allow.multiple=TRUE,
auto.key =list(space='right',cex=1.2,text=c('White','People of Color')))
title(main = "Average Daily Pop for Whatcom County for White and POC (People of Color): 2010 - 2014")

barchart(as.factor(Year) ~ White + Black + Hispanic + NatAmerican + Other + UnRace,origin=0,data=WAR1, stack = TRUE,
auto.key = list(text=c('White','Black','Hispanic','Native American','Other includes Asian','Unidentified Race')))
mtext("Stacked Sums: ADP for all jails WA across all Races WA: 2010 - 2014.",outer=TRUE,line=-7)

barchart(as.factor(Year) ~ Black + Hispanic + NatAmerican + Other + UnRace,origin=0, data=WAR1,stack=TRUE,
auto.key = list(text=c('Black','Hispanic','Native American','Other includes Asian','Unidentified Race')))
mtext("Stacked Sums: ADP for all jails WA for POC: 2010 - 2014.",outer=TRUE,line=-6)

barchart(as.factor(Year) ~ White + POC,origin=0,data=WAR1, stack = TRUE,
auto.key = list(text=c('White','People of Color')))
mtext("Stacked Sums: ADP for all jails WA White vs. POC: 2010 - 2014.",outer=TRUE,line=-6)

#barchart(as.factor(Year) ~ White + Black + Hispanic + NatAmerican + Other + UnRace, data=wR1, stack = TRUE,
#auto.key = list(text=c('White','Black','Hispanic','Native American','Other includes Asian','Unidentified Race')))
#mtext("Stacked Sums of Average Daily Bed rates for all jails WA across all Races WA: 2010 - 2014.",line=3)

#barchart(as.factor(Year) ~ Black + Hispanic + NatAmerican + Other + UnRace, data=wR1,stack=TRUE,
#auto.key = list(text=c('Black','Hispanic','Native American','Other includes Asian','Unidentified Race')))
#mtext("Stacked Sums of Average Daily Bed rates for all jails WA across all Races WA: 2010 - 2014.",line=3)

barchart(as.factor(Year) ~ White + POC, data=wR1,stack=TRUE,
auto.key = list(text=c('White','POC')))
mtext("Stacked Sums: ADP for Whatcom White vs. POC: 2010 - 2014.",outer=TRUE,line=-6)

plot.new(); barchart(as.factor(Jail) ~ White + Black + Hispanic + NatAmerican + Other + UnRace | Year,origin=0,
data=sqldf("Select *  From 'J.10.14' where Jail = 'Whatcom' or Jail = 'Skagit' or Jail = 'Yakima' or Jail = 'Clallam'"),auto.key=TRUE)
mtext("ADP from across all races by Year: 2010 - 2014 (B->T & L->R)",line=3,col="red")
plot.new(); barchart(as.factor(Jail) ~ White | Year,origin=0,
data=sqldf("Select *  From 'J.10.14' where Jail = 'Whatcom' or Jail = 'Skagit' or Jail = 'Yakima' or Jail = 'Clallam'"),auto.key=TRUE);
mtext("ADP For White Only by Year: 2010 - 2014 (B->T & L->R)",line=3,col="red")
plot.new(); barchart(as.factor(Jail) ~ Black + Hispanic + NatAmerican + Other + UnRace | Year,origin=0,
data=sqldf("Select *  From 'J.10.14' where Jail = 'Whatcom' or Jail = 'Skagit' or Jail = 'Yakima' or Jail = 'Clallam'"),auto.key=TRUE)
mtext("ADP from across those not white or unknown by Years: 2010 - 2014 (B->T & L->R)",line=3,col="red")
plot.new(); barchart(as.factor(Jail) ~ NatAmerican | Year,origin=0,
data=sqldf("Select *  From 'J.10.14' where Jail = 'King' or Jail = 'Yakima' or Jail = 'Whatcom' or Jail = 'Snohomish' or Jail ='Spokane'"),auto.key=TRUE)
mtext("Average Daily Pop",line=3)
plot.new(); barchart(as.factor(Jail) ~ Hispanic | Year,origin=0,
data=sqldf("Select *  From 'J.10.14' where Jail = 'King' or Jail = 'Yakima' or Jail = 'Whatcom' or Jail = 'Snohomish' or Jail ='Spokane'"),auto.key=TRUE)
mtext("Average Daily Pop",line=3)
plot.new(); barchart(as.factor(Jail) ~ Black | Year,origin=0,
data=sqldf("Select *  From 'J.10.14' where Jail = 'King' or Jail = 'Yakima' or Jail = 'Whatcom' or Jail = 'Snohomish' or Jail ='Spokane'"),auto.key=TRUE)
mtext("Average Daily Pop",line=3)

#nominal
barchart(Jail ~ NatAmerican,origin=0,data=nom,xlab = list(cex=1),ylab = list(cex=.6));
mtext("2014 Average Daily Pop",line=2)
barchart(Jail ~ Black,origin=0,data=nom);mtext("2014 Average Daily Pop",line=2)
mtext("2014 Average Daily Pop",line=2)
barchart(Jail ~ Hispanic,origin=0,data=nom);mtext("2014 Average Daily Pop",line=2)
mtext("2014 Average Daily Pop",line=2)

#percent
barchart(Jail ~ NatAmerican.AveDailyPop,origin=0,data=pct,xlab="Native American / DailyPop (averages)");mtext("Percentage 2014 ADP",line=2)
barchart(Jail ~ Black.AveDailyPop,origin=0,data=pct, xlab="Black / DailyPop (averages)");mtext("Percentage 2014 ADP",line=2)
barchart(Jail ~ Hispanic.AveDailyPop,origin=0,data=pct,xlab="Hispanic / DailyPop (averages)");mtext("Percentage 2014 ADP",line=2)
barchart(Jail ~ Hispanic.AveDailyPop,origin=0,data=pct,xlab="Hispanic / DailyPop (averages)");mtext("Percentage 2014 ADP",line=2)

# not working
# strip=strip.custom(factor.levels=Years),
# strip.names = strip.custom(factor.levels = c("2010","2011","2012","2013","2014")),

No comments:

Post a Comment