Minorities and whites stopped by tract
gpclibPermit()
## Warning in gpclibPermit(): support for gpclib will be withdrawn from
## maptools at the next major release
## [1] TRUE
gpclibPermitStatus()
## [1] TRUE
towntracts <- readOGR(dsn="maps", layer="census_tracts")
## OGR data source with driver: ESRI Shapefile
## Source: "maps", layer: "census_tracts"
## with 833 features
## It has 14 fields
towntracts_only <- towntracts
towntracts <- fortify(towntracts, region="GEOID10")
tracts2towns <- read.csv("maps/tracts_to_towns.csv", stringsAsFactors=FALSE)
colnames(tracts2towns) <- c("id", "town_name")
tracts2towns$id <- as.character(tracts2towns$id)
tracts2towns$id <- paste0("0", tracts2towns$id)
tracts2towns$town_name <- str_trim(tracts2towns$town_name)
# Minority stops
coords <- subset(stops, ethnicity=="Minority")
coords <- coords[c("InterventionLocationLongitude", "InterventionLocationLatitude")]
coords <- coords[complete.cases(coords),]
sp <- SpatialPoints(coords)
proj4string(sp) <- "+proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0"
proj4string(sp)
## [1] "+proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0"
plot(towntracts_only)
plot(sp, col="red" , add=TRUE)

by_tract <- over(sp, towntracts_only)
by_tract <- by_tract %>%
group_by(GEOID10) %>%
summarise(total=n())
by_tract <- by_tract[!is.na(by_tract$GEOID10),]
colnames(by_tract) <- c("id", "total")
by_tract$id <- as.character(by_tract$id)
by_tract <- left_join(by_tract, tracts2towns)
## Joining by: "id"
by_tract <- subset(by_tract, town_name!="Scotland")
adjacent <- read.csv("data/adjacent_search.csv", stringsAsFactors = FALSE)
by_tract <- left_join(by_tract, adjacent)
## Joining by: "town_name"
minority_tracts <- by_tract
# White stops
coords <- subset(stops, ethnicity=="White")
coords <- coords[c("InterventionLocationLongitude", "InterventionLocationLatitude")]
coords <- coords[complete.cases(coords),]
sp <- SpatialPoints(coords)
proj4string(sp) <- "+proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0"
proj4string(sp)
## [1] "+proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0"
plot(towntracts_only)
plot(sp, col="red" , add=TRUE)

by_tract <- over(sp, towntracts_only)
by_tract <- by_tract %>%
group_by(GEOID10) %>%
summarise(total=n())
by_tract <- by_tract[!is.na(by_tract$GEOID10),]
colnames(by_tract) <- c("id", "total")
by_tract$id <- as.character(by_tract$id)
by_tract <- left_join(by_tract, tracts2towns)
## Joining by: "id"
by_tract <- subset(by_tract, town_name!="Scotland")
adjacent <- read.csv("data/adjacent_search.csv", stringsAsFactors = FALSE)
by_tract <- left_join(by_tract, adjacent)
## Joining by: "town_name"
by_tract <- by_tract[c("id", "total")]
colnames(by_tract) <- c("id", "white")
mw_tract <- left_join(minority_tracts, by_tract)
## Joining by: "id"
mw_tract$minority_p <- round(mw_tract$total/(mw_tract$total+mw_tract$white)*100,2)
mw_tract$white_p <- round(mw_tract$white/(mw_tract$total+mw_tract$white)*100,2)
total_map <- left_join(towntracts, mw_tract)
## Joining by: "id"
# Black stops
coords <- subset(stops, RE=="Black")
coords <- coords[c("InterventionLocationLongitude", "InterventionLocationLatitude")]
coords <- coords[complete.cases(coords),]
sp <- SpatialPoints(coords)
proj4string(sp) <- "+proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0"
proj4string(sp)
## [1] "+proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0"
plot(towntracts_only)
plot(sp, col="red" , add=TRUE)

by_tract <- over(sp, towntracts_only)
by_tract <- by_tract %>%
group_by(GEOID10) %>%
summarise(total=n())
by_tract <- by_tract[!is.na(by_tract$GEOID10),]
colnames(by_tract) <- c("id", "total")
by_tract$id <- as.character(by_tract$id)
by_tract <- left_join(by_tract, tracts2towns)
## Joining by: "id"
by_tract <- subset(by_tract, town_name!="Scotland")
adjacent <- read.csv("data/adjacent_search.csv", stringsAsFactors = FALSE)
by_tract <- left_join(by_tract, adjacent)
## Joining by: "town_name"
by_tract <- by_tract[c("id", "total")]
colnames(by_tract) <- c("id", "black")
mw_tract <- left_join(mw_tract, by_tract)
## Joining by: "id"
mw_tract$black_p <- round(mw_tract$black/(mw_tract$total+mw_tract$white)*100,2)
total_map <- left_join(towntracts, mw_tract)
## Joining by: "id"
# Hispanic stops
coords <- subset(stops, RE=="Hispanic")
coords <- coords[c("InterventionLocationLongitude", "InterventionLocationLatitude")]
coords <- coords[complete.cases(coords),]
sp <- SpatialPoints(coords)
proj4string(sp) <- "+proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0"
proj4string(sp)
## [1] "+proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0"
plot(towntracts_only)
plot(sp, col="red" , add=TRUE)

by_tract <- over(sp, towntracts_only)
by_tract <- by_tract %>%
group_by(GEOID10) %>%
summarise(total=n())
by_tract <- by_tract[!is.na(by_tract$GEOID10),]
colnames(by_tract) <- c("id", "total")
by_tract$id <- as.character(by_tract$id)
by_tract <- left_join(by_tract, tracts2towns)
## Joining by: "id"
by_tract <- subset(by_tract, town_name!="Scotland")
adjacent <- read.csv("data/adjacent_search.csv", stringsAsFactors = FALSE)
by_tract <- left_join(by_tract, adjacent)
## Joining by: "town_name"
by_tract <- by_tract[c("id", "total")]
colnames(by_tract) <- c("id", "hispanic")
mw_tract <- left_join(mw_tract, by_tract)
## Joining by: "id"
mw_tract$hispanic_p <- round(mw_tract$hispanic/(mw_tract$total+mw_tract$white)*100,2)
write.csv(mw_tract, "data/tracts_stops.csv")
total_map <- left_join(towntracts, mw_tract)
## Joining by: "id"
## Minorities
tm_ct <- ggplot() +
geom_polygon(data = total_map, aes(x=long, y=lat, group=group, fill=total), color = "black", size=0.2) +
geom_polygon(data = total_map, aes(x=long, y=lat, group=group, fill=total), color = "black", size=0.2) +
coord_map() +
scale_fill_distiller(type="seq", trans="reverse", palette = "Reds", breaks=pretty_breaks(n=10)) +
theme_nothing(legend=TRUE) +
labs(title="Where minorities are pulled over", fill="")
print(tm_ct)

## Percent by town
pm_ct <- ggplot() +
geom_polygon(data = total_map, aes(x=long, y=lat, group=group, fill=minority_p), color = "black", size=0.2) +
geom_polygon(data = total_map, aes(x=long, y=lat, group=group, fill=minority_p), color = "black", size=0.2) +
coord_map() +
scale_fill_distiller(type="seq", trans="reverse", palette = "Reds", breaks=pretty_breaks(n=10)) +
theme_nothing(legend=TRUE) +
labs(title="Where minorities are pulled over (percent by tract)", fill="")
print(pm_ct)

## White drivers
tm_ct <- ggplot() +
geom_polygon(data = total_map, aes(x=long, y=lat, group=group, fill=white), color = "black", size=0.2) +
geom_polygon(data = total_map, aes(x=long, y=lat, group=group, fill=white), color = "black", size=0.2) +
coord_map() +
scale_fill_distiller(type="seq", trans="reverse", palette = "Reds", breaks=pretty_breaks(n=10)) +
theme_nothing(legend=TRUE) +
labs(title="Where White drivers are pulled over", fill="")
print(tm_ct)

## Percent by town
pm_ct <- ggplot() +
geom_polygon(data = total_map, aes(x=long, y=lat, group=group, fill=white_p), color = "black", size=0.2) +
geom_polygon(data = total_map, aes(x=long, y=lat, group=group, fill=white_p), color = "black", size=0.2) +
coord_map() +
scale_fill_distiller(type="seq", trans="reverse", palette = "Reds", breaks=pretty_breaks(n=10)) +
theme_nothing(legend=TRUE) +
labs(title="Where White drivers are pulled over (percent by tract)", fill="")
print(pm_ct)

## Black drivers
tm_ct <- ggplot() +
geom_polygon(data = total_map, aes(x=long, y=lat, group=group, fill=black), color = "black", size=0.2) +
geom_polygon(data = total_map, aes(x=long, y=lat, group=group, fill=black), color = "black", size=0.2) +
coord_map() +
scale_fill_distiller(type="seq", trans="reverse", palette = "Reds", breaks=pretty_breaks(n=10)) +
theme_nothing(legend=TRUE) +
labs(title="Where Black drivers are pulled over", fill="")
print(tm_ct)

## Percent by town
pm_ct <- ggplot() +
geom_polygon(data = total_map, aes(x=long, y=lat, group=group, fill=black_p), color = "black", size=0.2) +
geom_polygon(data = total_map, aes(x=long, y=lat, group=group, fill=black_p), color = "black", size=0.2) +
coord_map() +
scale_fill_distiller(type="seq", trans="reverse", palette = "Reds", breaks=pretty_breaks(n=10)) +
theme_nothing(legend=TRUE) +
labs(title="Where Black drivers are pulled over (percent by tract)", fill="")
print(pm_ct)

## Hispanic drivers
tm_ct <- ggplot() +
geom_polygon(data = total_map, aes(x=long, y=lat, group=group, fill=hispanic), color = "black", size=0.2) +
geom_polygon(data = total_map, aes(x=long, y=lat, group=group, fill=hispanic), color = "black", size=0.2) +
coord_map() +
scale_fill_distiller(type="seq", trans="reverse", palette = "Reds", breaks=pretty_breaks(n=10)) +
theme_nothing(legend=TRUE) +
labs(title="Where Hispanic drivers are pulled over", fill="")
print(tm_ct)

## Percent by town
pm_ct <- ggplot() +
geom_polygon(data = total_map, aes(x=long, y=lat, group=group, fill=hispanic_p), color = "black", size=0.2) +
geom_polygon(data = total_map, aes(x=long, y=lat, group=group, fill=hispanic_p), color = "black", size=0.2) +
coord_map() +
scale_fill_distiller(type="seq", trans="reverse", palette = "Reds", breaks=pretty_breaks(n=10)) +
theme_nothing(legend=TRUE) +
labs(title="Where Hispanic drivers are pulled over (percent by tract)", fill="")
print(pm_ct)

gpclibPermit()
## Warning in gpclibPermit(): support for gpclib will be withdrawn from
## maptools at the next major release
## [1] TRUE
gpclibPermitStatus()
## [1] TRUE
townborders <- readOGR(dsn="maps", layer="ctgeo")
## OGR data source with driver: ESRI Shapefile
## Source: "maps", layer: "ctgeo"
## with 169 features
## It has 6 fields
townborders_only <- townborders
townborders<- fortify(townborders, region="NAME10")
total_map <- subset(total_map, !is.na(town_name))
town_name <- "East Hartford"
#test_map <- subset(total_map, town_department==town_name)
test_map <- subset(total_map, town_department=="East Hartford")
test_map <- subset(test_map, !is.na(white_p))
test_borders <- subset(townborders, id==town_name)
# Hispanic
pm_ct <- ggplot()
pm_ct <- pm_ct + geom_polygon(data = test_map, aes(x=long, y=lat, group=group, fill=hispanic_p/100), color="white", size=.25)
pm_ct <- pm_ct + geom_polygon(data = test_borders, aes(x=long, y=lat, group=group), fill=NA, color = "black", size=0.5)
pm_ct <- pm_ct + coord_map()
pm_ct <- pm_ct + scale_fill_distiller(type="seq", trans="reverse", palette = "Reds", breaks=pretty_breaks(n=9), labels=percent, name="Stops")
pm_ct <- pm_ct + theme_nothing(legend=TRUE)
pm_ct <- pm_ct + labs(x=NULL, y=NULL, title=paste("Where Hispanic drivers are pulled over by", town_name, "police"))
#pm_ct <- pm_ct + theme_bw(base_family="Calibri")
#pm_ct <- pm_ct + theme(panel.grid.major=element_blank())
#pm_ct <- pm_ct + theme(panel.grid.minor=element_blank())
#pm_ct <- pm_ct + theme(panel.border=element_blank())
pm_ct <- pm_ct + theme(text = element_text(size=15))
#pm_ct <- pm_ct + theme(axis.ticks=element_blank())
#pm_ct <- pm_ct + theme(axis.text.x=element_blank())
pm_ct <- pm_ct + theme(plot.title=element_text(face="bold", hjust=.4))
pm_ct <- pm_ct + theme(plot.subtitle=element_text(face="italic", size=9, margin=margin(l=20)))
pm_ct <- pm_ct + theme(plot.caption=element_text(size=12, margin=margin(t=12), color="#7a7d7e", hjust=0))
#pm_ct <- pm_ct + scale_fill_gradient(low = "#b2b2b2", high = "tomato", labels = percent)
pm_ct <- pm_ct + annotate("segment", x = -72.58, xend = -72.675, y = 41.815, yend = 41.815, colour = "lightblue", size=.5)
pm_ct <- pm_ct + annotate("point", x = -72.58, y = 41.815, colour = "lightblue", size = 2)
pm_ct <- pm_ct + annotate("text", x = -72.71, y = 41.815, label = "South Windsor", size=5, colour="gray30")
pm_ct <- pm_ct + annotate("segment", x = -72.5, xend = -72.55, y = 41.75, yend = 41.71, colour = "lightblue", size=.5)
pm_ct <- pm_ct + annotate("point", x = -72.5, y = 41.75, colour = "lightblue", size = 2)
pm_ct <- pm_ct + annotate("text", x = -72.578, y = 41.71, label = "Manchester", size=5, colour="gray30")
pm_ct <- pm_ct + annotate("point", x = -72.75, y = 41.71, colour="white", size=.2)
pm_ct <- pm_ct + theme(legend.key.size = unit(1, "cm"))
pm_ct

# labs(title=" (percent by tract)", fill="")
print(pm_ct)

ggsave(pm_ct, file = "img/stops_easthartford_hispanic.png", width = 8, height = 6, type = "cairo-png")
# Black
pm_ct <- ggplot()
pm_ct <- pm_ct + geom_polygon(data = test_map, aes(x=long, y=lat, group=group, fill=black_p/100), color="white", size=.25)
pm_ct <- pm_ct + geom_polygon(data = test_borders, aes(x=long, y=lat, group=group), fill=NA, color = "black", size=0.5)
pm_ct <- pm_ct + coord_map()
pm_ct <- pm_ct + scale_fill_distiller(type="seq", trans="reverse", palette = "Reds", breaks=pretty_breaks(n=9), labels=percent, name="Stops")
pm_ct <- pm_ct + theme_nothing(legend=TRUE)
pm_ct <- pm_ct + labs(x=NULL, y=NULL, title=paste("Where black drivers are pulled over by", town_name, "police"))
#pm_ct <- pm_ct + theme_bw(base_family="Calibri")
#pm_ct <- pm_ct + theme(panel.grid.major=element_blank())
#pm_ct <- pm_ct + theme(panel.grid.minor=element_blank())
#pm_ct <- pm_ct + theme(panel.border=element_blank())
pm_ct <- pm_ct + theme(text = element_text(size=15))
#pm_ct <- pm_ct + theme(axis.ticks=element_blank())
#pm_ct <- pm_ct + theme(axis.text.x=element_blank())
pm_ct <- pm_ct + theme(plot.title=element_text(face="bold", hjust=.4))
pm_ct <- pm_ct + theme(plot.subtitle=element_text(face="italic", size=9, margin=margin(l=20)))
pm_ct <- pm_ct + theme(plot.caption=element_text(size=12, margin=margin(t=12), color="#7a7d7e", hjust=0))
#pm_ct <- pm_ct + scale_fill_gradient(low = "#b2b2b2", high = "tomato", labels = percent)
pm_ct <- pm_ct + annotate("segment", x = -72.58, xend = -72.675, y = 41.815, yend = 41.815, colour = "lightblue", size=.5)
pm_ct <- pm_ct + annotate("point", x = -72.58, y = 41.815, colour = "lightblue", size = 2)
pm_ct <- pm_ct + annotate("text", x = -72.71, y = 41.815, label = "South Windsor", size=5, colour="gray30")
pm_ct <- pm_ct + annotate("segment", x = -72.5, xend = -72.55, y = 41.75, yend = 41.71, colour = "lightblue", size=.5)
pm_ct <- pm_ct + annotate("point", x = -72.5, y = 41.75, colour = "lightblue", size = 2)
pm_ct <- pm_ct + annotate("text", x = -72.578, y = 41.71, label = "Manchester", size=5, colour="gray30")
pm_ct <- pm_ct + annotate("point", x = -72.75, y = 41.71, colour="white", size=.2)
pm_ct <- pm_ct + theme(legend.key.size = unit(1, "cm"))
pm_ct

# labs(title=" (percent by tract)", fill="")
print(pm_ct)

ggsave(pm_ct, file = "img/stops_easthartford_black.png", width = 8, height = 6, type = "cairo-png")
# Minorities
pm_ct <- ggplot()
pm_ct <- pm_ct + geom_polygon(data = test_map, aes(x=long, y=lat, group=group, fill=minority_p/100), color="white", size=.25)
pm_ct <- pm_ct + geom_polygon(data = test_borders, aes(x=long, y=lat, group=group), fill=NA, color = "black", size=0.5)
pm_ct <- pm_ct + coord_map()
pm_ct <- pm_ct + scale_fill_distiller(type="seq", trans="reverse", palette = "Reds", breaks=pretty_breaks(n=9), labels=percent, name="Stops")
pm_ct <- pm_ct + theme_nothing(legend=TRUE)
pm_ct <- pm_ct + labs(x=NULL, y=NULL, title=paste("Where minority drivers are pulled over by", town_name, "police"))
#pm_ct <- pm_ct + theme_bw(base_family="Calibri")
#pm_ct <- pm_ct + theme(panel.grid.major=element_blank())
#pm_ct <- pm_ct + theme(panel.grid.minor=element_blank())
#pm_ct <- pm_ct + theme(panel.border=element_blank())
pm_ct <- pm_ct + theme(text = element_text(size=15))
#pm_ct <- pm_ct + theme(axis.ticks=element_blank())
#pm_ct <- pm_ct + theme(axis.text.x=element_blank())
pm_ct <- pm_ct + theme(plot.title=element_text(face="bold", hjust=.4))
pm_ct <- pm_ct + theme(plot.subtitle=element_text(face="italic", size=9, margin=margin(l=20)))
pm_ct <- pm_ct + theme(plot.caption=element_text(size=12, margin=margin(t=12), color="#7a7d7e", hjust=0))
#pm_ct <- pm_ct + scale_fill_gradient(low = "#b2b2b2", high = "tomato", labels = percent)
pm_ct <- pm_ct + annotate("segment", x = -72.58, xend = -72.675, y = 41.815, yend = 41.815, colour = "lightblue", size=.5)
pm_ct <- pm_ct + annotate("point", x = -72.58, y = 41.815, colour = "lightblue", size = 2)
pm_ct <- pm_ct + annotate("text", x = -72.71, y = 41.815, label = "South Windsor", size=5, colour="gray30")
pm_ct <- pm_ct + annotate("segment", x = -72.5, xend = -72.55, y = 41.75, yend = 41.71, colour = "lightblue", size=.5)
pm_ct <- pm_ct + annotate("point", x = -72.5, y = 41.75, colour = "lightblue", size = 2)
pm_ct <- pm_ct + annotate("text", x = -72.578, y = 41.71, label = "Manchester", size=5, colour="gray30")
pm_ct <- pm_ct + annotate("point", x = -72.75, y = 41.71, colour="white", size=.2)
pm_ct <- pm_ct + theme(legend.key.size = unit(1, "cm"))
pm_ct

# labs(title=" (percent by tract)", fill="")
print(pm_ct)

ggsave(pm_ct, file = "img/stops_easthartford_minorities.png", width = 8, height = 6, type = "cairo-png")
# White
pm_ct <- ggplot()
pm_ct <- pm_ct + geom_polygon(data = test_map, aes(x=long, y=lat, group=group, fill=white_p/100), color="white", size=.25)
pm_ct <- pm_ct + geom_polygon(data = test_borders, aes(x=long, y=lat, group=group), fill=NA, color = "black", size=0.5)
pm_ct <- pm_ct + coord_map()
pm_ct <- pm_ct + scale_fill_distiller(type="seq", trans="reverse", palette = "Reds", breaks=pretty_breaks(n=9), labels=percent, name="Stops")
pm_ct <- pm_ct + theme_nothing(legend=TRUE)
pm_ct <- pm_ct + labs(x=NULL, y=NULL, title=paste("Where white drivers are pulled over by", town_name, "police"))
#pm_ct <- pm_ct + theme_bw(base_family="Calibri")
#pm_ct <- pm_ct + theme(panel.grid.major=element_blank())
#pm_ct <- pm_ct + theme(panel.grid.minor=element_blank())
#pm_ct <- pm_ct + theme(panel.border=element_blank())
pm_ct <- pm_ct + theme(text = element_text(size=15))
#pm_ct <- pm_ct + theme(axis.ticks=element_blank())
#pm_ct <- pm_ct + theme(axis.text.x=element_blank())
pm_ct <- pm_ct + theme(plot.title=element_text(face="bold", hjust=.4))
pm_ct <- pm_ct + theme(plot.subtitle=element_text(face="italic", size=9, margin=margin(l=20)))
pm_ct <- pm_ct + theme(plot.caption=element_text(size=12, margin=margin(t=12), color="#7a7d7e", hjust=0))
#pm_ct <- pm_ct + scale_fill_gradient(low = "#b2b2b2", high = "tomato", labels = percent)
pm_ct <- pm_ct + annotate("segment", x = -72.58, xend = -72.675, y = 41.815, yend = 41.815, colour = "lightblue", size=.5)
pm_ct <- pm_ct + annotate("point", x = -72.58, y = 41.815, colour = "lightblue", size = 2)
pm_ct <- pm_ct + annotate("text", x = -72.71, y = 41.815, label = "South Windsor", size=5, colour="gray30")
pm_ct <- pm_ct + annotate("segment", x = -72.5, xend = -72.55, y = 41.75, yend = 41.71, colour = "lightblue", size=.5)
pm_ct <- pm_ct + annotate("point", x = -72.5, y = 41.75, colour = "lightblue", size = 2)
pm_ct <- pm_ct + annotate("text", x = -72.578, y = 41.71, label = "Manchester", size=5, colour="gray30")
pm_ct <- pm_ct + annotate("point", x = -72.75, y = 41.71, colour="white", size=.2)
pm_ct <- pm_ct + theme(legend.key.size = unit(1, "cm"))
pm_ct

# labs(title=" (percent by tract)", fill="")
print(pm_ct)

ggsave(pm_ct, file = "img/stops_easthartford_white.png", width = 8, height = 6, type = "cairo-png")
town_name <- "Granby"
#test_map <- subset(total_map, town_department==town_name)
test_map <- subset(total_map, town_department=="Granby")
test_map <- subset(test_map, !is.na(white_p))
test_borders <- subset(townborders, id==town_name)
# Hispanic
pm_ct <- ggplot()
pm_ct <- pm_ct + geom_polygon(data = test_map, aes(x=long, y=lat, group=group, fill=hispanic_p/100), color="white", size=.25)
pm_ct <- pm_ct + geom_polygon(data = test_borders, aes(x=long, y=lat, group=group), fill=NA, color = "black", size=0.5)
pm_ct <- pm_ct + coord_map()
pm_ct <- pm_ct + scale_fill_distiller(type="seq", trans="reverse", palette = "Reds", breaks=pretty_breaks(n=9), labels=percent, name="Stops")
pm_ct <- pm_ct + theme_nothing(legend=TRUE)
pm_ct <- pm_ct + labs(x=NULL, y=NULL, title=paste("Where Hispanic drivers are pulled over by", town_name, "police"))
#pm_ct <- pm_ct + theme_bw(base_family="Calibri")
#pm_ct <- pm_ct + theme(panel.grid.major=element_blank())
#pm_ct <- pm_ct + theme(panel.grid.minor=element_blank())
#pm_ct <- pm_ct + theme(panel.border=element_blank())
pm_ct <- pm_ct + theme(text = element_text(size=15))
#pm_ct <- pm_ct + theme(axis.ticks=element_blank())
#pm_ct <- pm_ct + theme(axis.text.x=element_blank())
pm_ct <- pm_ct + theme(plot.title=element_text(face="bold", hjust=.4))
pm_ct <- pm_ct + theme(plot.subtitle=element_text(face="italic", size=9, margin=margin(l=20)))
pm_ct <- pm_ct + theme(plot.caption=element_text(size=12, margin=margin(t=12), color="#7a7d7e", hjust=0))
pm_ct

# labs(title=" (percent by tract)", fill="")
print(pm_ct)

ggsave(pm_ct, file = "img/stops_granby_hispanic.png", width = 8, height = 6, type = "cairo-png")
# Black
pm_ct <- ggplot()
pm_ct <- pm_ct + geom_polygon(data = test_map, aes(x=long, y=lat, group=group, fill=black_p/100), color="white", size=.25)
pm_ct <- pm_ct + geom_polygon(data = test_borders, aes(x=long, y=lat, group=group), fill=NA, color = "black", size=0.5)
pm_ct <- pm_ct + coord_map()
pm_ct <- pm_ct + scale_fill_distiller(type="seq", trans="reverse", palette = "Reds", breaks=pretty_breaks(n=9), labels=percent, name="Stops")
pm_ct <- pm_ct + theme_nothing(legend=TRUE)
pm_ct <- pm_ct + labs(x=NULL, y=NULL, title=paste("Where black drivers are pulled over by", town_name, "police"))
#pm_ct <- pm_ct + theme_bw(base_family="Calibri")
#pm_ct <- pm_ct + theme(panel.grid.major=element_blank())
#pm_ct <- pm_ct + theme(panel.grid.minor=element_blank())
#pm_ct <- pm_ct + theme(panel.border=element_blank())
pm_ct <- pm_ct + theme(text = element_text(size=15))
#pm_ct <- pm_ct + theme(axis.ticks=element_blank())
#pm_ct <- pm_ct + theme(axis.text.x=element_blank())
pm_ct <- pm_ct + theme(plot.title=element_text(face="bold", hjust=.4))
pm_ct <- pm_ct + theme(plot.subtitle=element_text(face="italic", size=9, margin=margin(l=20)))
pm_ct <- pm_ct + theme(plot.caption=element_text(size=12, margin=margin(t=12), color="#7a7d7e", hjust=0))
#pm_ct <- pm_ct + scale_fill_gradient(low = "#b2b2b2", high = "tomato", labels = percent)
pm_ct

# labs(title=" (percent by tract)", fill="")
print(pm_ct)

ggsave(pm_ct, file = "img/stops_granby_black.png", width = 8, height = 6, type = "cairo-png")
# Minorities
pm_ct <- ggplot()
pm_ct <- pm_ct + geom_polygon(data = test_map, aes(x=long, y=lat, group=group, fill=minority_p/100), color="white", size=.25)
pm_ct <- pm_ct + geom_polygon(data = test_borders, aes(x=long, y=lat, group=group), fill=NA, color = "black", size=0.5)
pm_ct <- pm_ct + coord_map()
pm_ct <- pm_ct + scale_fill_distiller(type="seq", trans="reverse", palette = "Reds", breaks=pretty_breaks(n=9), labels=percent, name="Stops")
pm_ct <- pm_ct + theme_nothing(legend=TRUE)
pm_ct <- pm_ct + labs(x=NULL, y=NULL, title=paste("Where minority drivers are pulled over by", town_name, "police"))
#pm_ct <- pm_ct + theme_bw(base_family="Calibri")
#pm_ct <- pm_ct + theme(panel.grid.major=element_blank())
#pm_ct <- pm_ct + theme(panel.grid.minor=element_blank())
#pm_ct <- pm_ct + theme(panel.border=element_blank())
pm_ct <- pm_ct + theme(text = element_text(size=15))
#pm_ct <- pm_ct + theme(axis.ticks=element_blank())
#pm_ct <- pm_ct + theme(axis.text.x=element_blank())
pm_ct <- pm_ct + theme(plot.title=element_text(face="bold", hjust=.4))
pm_ct <- pm_ct + theme(plot.subtitle=element_text(face="italic", size=9, margin=margin(l=20)))
pm_ct <- pm_ct + theme(plot.caption=element_text(size=12, margin=margin(t=12), color="#7a7d7e", hjust=0))
#pm_ct <- pm_ct + scale_fill_gradient(low = "#b2b2b2", high = "tomato", labels = percent)
pm_ct

# labs(title=" (percent by tract)", fill="")
print(pm_ct)

ggsave(pm_ct, file = "img/stops_granby_minorities.png", width = 8, height = 6, type = "cairo-png")
# White
pm_ct <- ggplot()
pm_ct <- pm_ct + geom_polygon(data = test_map, aes(x=long, y=lat, group=group, fill=white_p/100), color="white", size=.25)
pm_ct <- pm_ct + geom_polygon(data = test_borders, aes(x=long, y=lat, group=group), fill=NA, color = "black", size=0.5)
pm_ct <- pm_ct + coord_map()
pm_ct <- pm_ct + scale_fill_distiller(type="seq", trans="reverse", palette = "Reds", breaks=pretty_breaks(n=9), labels=percent, name="Stops")
pm_ct <- pm_ct + theme_nothing(legend=TRUE)
pm_ct <- pm_ct + labs(x=NULL, y=NULL, title=paste("Where white drivers are pulled over by", town_name, "police"))
#pm_ct <- pm_ct + theme_bw(base_family="Calibri")
#pm_ct <- pm_ct + theme(panel.grid.major=element_blank())
#pm_ct <- pm_ct + theme(panel.grid.minor=element_blank())
#pm_ct <- pm_ct + theme(panel.border=element_blank())
pm_ct <- pm_ct + theme(text = element_text(size=15))
#pm_ct <- pm_ct + theme(axis.ticks=element_blank())
#pm_ct <- pm_ct + theme(axis.text.x=element_blank())
pm_ct <- pm_ct + theme(plot.title=element_text(face="bold", hjust=.4))
pm_ct <- pm_ct + theme(plot.subtitle=element_text(face="italic", size=9, margin=margin(l=20)))
pm_ct <- pm_ct + theme(plot.caption=element_text(size=12, margin=margin(t=12), color="#7a7d7e", hjust=0))
#pm_ct <- pm_ct + scale_fill_gradient(low = "#b2b2b2", high = "tomato", labels = percent)
pm_ct

# labs(title=" (percent by tract)", fill="")
print(pm_ct)

ggsave(pm_ct, file = "img/stops_granby_white.png", width = 8, height = 6, type = "cairo-png")
town_name <- "Groton Town"
#test_map <- subset(total_map, town_department==town_name)
test_map <- subset(total_map, town_department=="Groton Town")
test_map <- subset(test_map, !is.na(white_p))
test_borders <- subset(townborders, id=="Groton")
# Hispanic
pm_ct <- ggplot()
pm_ct <- pm_ct + geom_polygon(data = test_map, aes(x=long, y=lat, group=group, fill=hispanic_p/100), color="white", size=.25)
#pm_ct <- pm_ct + geom_polygon(data = test_borders, aes(x=long, y=lat, group=group), fill=NA, color = "black", size=0.5)
pm_ct <- pm_ct + coord_map()
pm_ct <- pm_ct + scale_fill_distiller(type="seq", trans="reverse", palette = "Reds", breaks=pretty_breaks(n=9), labels=percent, name="Stops")
pm_ct <- pm_ct + theme_nothing(legend=TRUE)
pm_ct <- pm_ct + labs(x=NULL, y=NULL, title=paste("Where Hispanic drivers are pulled over by", town_name, "police"))
#pm_ct <- pm_ct + theme_bw(base_family="Calibri")
#pm_ct <- pm_ct + theme(panel.grid.major=element_blank())
#pm_ct <- pm_ct + theme(panel.grid.minor=element_blank())
#pm_ct <- pm_ct + theme(panel.border=element_blank())
pm_ct <- pm_ct + theme(text = element_text(size=15))
#pm_ct <- pm_ct + theme(axis.ticks=element_blank())
#pm_ct <- pm_ct + theme(axis.text.x=element_blank())
pm_ct <- pm_ct + theme(plot.title=element_text(face="bold", hjust=.4))
pm_ct <- pm_ct + theme(plot.subtitle=element_text(face="italic", size=9, margin=margin(l=20)))
pm_ct <- pm_ct + theme(plot.caption=element_text(size=12, margin=margin(t=12), color="#7a7d7e", hjust=0))
#pm_ct <- pm_ct + scale_fill_gradient(low = "#b2b2b2", high = "tomato", labels = percent)
pm_ct <- pm_ct + theme(legend.key.size = unit(1, "cm"))
pm_ct

# labs(title=" (percent by tract)", fill="")
print(pm_ct)

ggsave(pm_ct, file = "img/stops_grotontown_hispanic.png", width = 8, height = 6, type = "cairo-png")
# Black
pm_ct <- ggplot()
pm_ct <- pm_ct + geom_polygon(data = test_map, aes(x=long, y=lat, group=group, fill=black_p/100), color="white", size=.25)
#pm_ct <- pm_ct + geom_polygon(data = test_borders, aes(x=long, y=lat, group=group), fill=NA, color = "black", size=0.5)
pm_ct <- pm_ct + coord_map()
pm_ct <- pm_ct + scale_fill_distiller(type="seq", trans="reverse", palette = "Reds", breaks=pretty_breaks(n=9), labels=percent, name="Stops")
pm_ct <- pm_ct + theme_nothing(legend=TRUE)
pm_ct <- pm_ct + labs(x=NULL, y=NULL, title=paste("Where black drivers are pulled over by", town_name, "police"))
#pm_ct <- pm_ct + theme_bw(base_family="Calibri")
#pm_ct <- pm_ct + theme(panel.grid.major=element_blank())
#pm_ct <- pm_ct + theme(panel.grid.minor=element_blank())
#pm_ct <- pm_ct + theme(panel.border=element_blank())
pm_ct <- pm_ct + theme(text = element_text(size=15))
#pm_ct <- pm_ct + theme(axis.ticks=element_blank())
#pm_ct <- pm_ct + theme(axis.text.x=element_blank())
pm_ct <- pm_ct + theme(plot.title=element_text(face="bold", hjust=.4))
pm_ct <- pm_ct + theme(plot.subtitle=element_text(face="italic", size=9, margin=margin(l=20)))
pm_ct <- pm_ct + theme(plot.caption=element_text(size=12, margin=margin(t=12), color="#7a7d7e", hjust=0))
#pm_ct <- pm_ct + scale_fill_gradient(low = "#b2b2b2", high = "tomato", labels = percent)
pm_ct <- pm_ct + theme(legend.key.size = unit(1, "cm"))
pm_ct

# labs(title=" (percent by tract)", fill="")
print(pm_ct)

ggsave(pm_ct, file = "img/stops_grotontown_black.png", width = 8, height = 6, type = "cairo-png")
# Minorities
pm_ct <- ggplot()
pm_ct <- pm_ct + geom_polygon(data = test_map, aes(x=long, y=lat, group=group, fill=minority_p/100), color="white", size=.25)
#pm_ct <- pm_ct + geom_polygon(data = test_borders, aes(x=long, y=lat, group=group), fill=NA, color = "black", size=0.5)
pm_ct <- pm_ct + coord_map()
pm_ct <- pm_ct + scale_fill_distiller(type="seq", trans="reverse", palette = "Reds", breaks=pretty_breaks(n=9), labels=percent, name="Stops")
pm_ct <- pm_ct + theme_nothing(legend=TRUE)
pm_ct <- pm_ct + labs(x=NULL, y=NULL, title=paste("Where minority drivers are pulled over by", town_name, "police"))
#pm_ct <- pm_ct + theme_bw(base_family="Calibri")
#pm_ct <- pm_ct + theme(panel.grid.major=element_blank())
#pm_ct <- pm_ct + theme(panel.grid.minor=element_blank())
#pm_ct <- pm_ct + theme(panel.border=element_blank())
pm_ct <- pm_ct + theme(text = element_text(size=15))
#pm_ct <- pm_ct + theme(axis.ticks=element_blank())
#pm_ct <- pm_ct + theme(axis.text.x=element_blank())
pm_ct <- pm_ct + theme(plot.title=element_text(face="bold", hjust=.4))
pm_ct <- pm_ct + theme(plot.subtitle=element_text(face="italic", size=9, margin=margin(l=20)))
pm_ct <- pm_ct + theme(plot.caption=element_text(size=12, margin=margin(t=12), color="#7a7d7e", hjust=0))
#pm_ct <- pm_ct + scale_fill_gradient(low = "#b2b2b2", high = "tomato", labels = percent)
pm_ct <- pm_ct + theme(legend.key.size = unit(1, "cm"))
pm_ct

# labs(title=" (percent by tract)", fill="")
print(pm_ct)

ggsave(pm_ct, file = "img/stops_grotontown_minorities.png", width = 8, height = 6, type = "cairo-png")
# White
pm_ct <- ggplot()
pm_ct <- pm_ct + geom_polygon(data = test_map, aes(x=long, y=lat, group=group, fill=white_p/100), color="white", size=.25)
#pm_ct <- pm_ct + geom_polygon(data = test_borders, aes(x=long, y=lat, group=group), fill=NA, color = "black", size=0.5)
pm_ct <- pm_ct + coord_map()
pm_ct <- pm_ct + scale_fill_distiller(type="seq", trans="reverse", palette = "Reds", breaks=pretty_breaks(n=9), labels=percent, name="Stops")
pm_ct <- pm_ct + theme_nothing(legend=TRUE)
pm_ct <- pm_ct + labs(x=NULL, y=NULL, title=paste("Where white drivers are pulled over by", town_name, "police"))
#pm_ct <- pm_ct + theme_bw(base_family="Calibri")
#pm_ct <- pm_ct + theme(panel.grid.major=element_blank())
#pm_ct <- pm_ct + theme(panel.grid.minor=element_blank())
#pm_ct <- pm_ct + theme(panel.border=element_blank())
pm_ct <- pm_ct + theme(text = element_text(size=15))
#pm_ct <- pm_ct + theme(axis.ticks=element_blank())
#pm_ct <- pm_ct + theme(axis.text.x=element_blank())
pm_ct <- pm_ct + theme(plot.title=element_text(face="bold", hjust=.4))
pm_ct <- pm_ct + theme(plot.subtitle=element_text(face="italic", size=9, margin=margin(l=20)))
pm_ct <- pm_ct + theme(plot.caption=element_text(size=12, margin=margin(t=12), color="#7a7d7e", hjust=0))
#pm_ct <- pm_ct + scale_fill_gradient(low = "#b2b2b2", high = "tomato", labels = percent)
pm_ct <- pm_ct + theme(legend.key.size = unit(1, "cm"))
pm_ct

# labs(title=" (percent by tract)", fill="")
print(pm_ct)

ggsave(pm_ct, file = "img/stops_grotontown_white.png", width = 8, height = 6, type = "cairo-png")
town_name <- "Hamden"
#test_map <- subset(total_map, town_department==town_name)
test_map <- subset(total_map, town_department=="Hamden")
test_map <- subset(test_map, !is.na(white_p))
test_borders <- subset(townborders, id==town_name)
# Hispanic
pm_ct <- ggplot()
pm_ct <- pm_ct + geom_polygon(data = test_map, aes(x=long, y=lat, group=group, fill=hispanic_p/100), color="white", size=.25)
pm_ct <- pm_ct + geom_polygon(data = test_borders, aes(x=long, y=lat, group=group), fill=NA, color = "black", size=0.5)
pm_ct <- pm_ct + coord_map()
pm_ct <- pm_ct + scale_fill_distiller(type="seq", trans="reverse", palette = "Reds", breaks=pretty_breaks(n=9), labels=percent, name="Stops")
pm_ct <- pm_ct + theme_nothing(legend=TRUE)
pm_ct <- pm_ct + labs(x=NULL, y=NULL, title=paste("Where Hispanic drivers are pulled over by", town_name, "police"))
#pm_ct <- pm_ct + theme_bw(base_family="Calibri")
#pm_ct <- pm_ct + theme(panel.grid.major=element_blank())
#pm_ct <- pm_ct + theme(panel.grid.minor=element_blank())
#pm_ct <- pm_ct + theme(panel.border=element_blank())
pm_ct <- pm_ct + theme(text = element_text(size=15))
#pm_ct <- pm_ct + theme(axis.ticks=element_blank())
#pm_ct <- pm_ct + theme(axis.text.x=element_blank())
pm_ct <- pm_ct + theme(plot.title=element_text(face="bold", hjust=.4))
pm_ct <- pm_ct + theme(plot.subtitle=element_text(face="italic", size=9, margin=margin(l=20)))
pm_ct <- pm_ct + theme(plot.caption=element_text(size=12, margin=margin(t=12), color="#7a7d7e", hjust=0))
#pm_ct <- pm_ct + scale_fill_gradient(low = "#b2b2b2", high = "tomato", labels = percent)
pm_ct <- pm_ct + annotate("segment", x = -73.07, xend = -73.05, y = 41.375, yend = 41.4, colour = "lightblue", size=.5)
pm_ct <- pm_ct + annotate("point", x = -73.07, y = 41.375, colour = "lightblue", size = 2)
pm_ct <- pm_ct + annotate("text", x = -73.033, y = 41.404, label = "Seymour", size=5, colour="gray30")
pm_ct <- pm_ct + annotate("segment", x = -72.93, xend = -72.87, y = 41.325, yend = 41.325, colour = "lightblue", size=.5)
pm_ct <- pm_ct + annotate("point", x = -72.93, y = 41.325, colour = "lightblue", size = 2)
pm_ct <- pm_ct + annotate("text", x = -72.85, y = 41.325, label = "New Haven", size=5, colour="gray30")
pm_ct <- pm_ct + annotate("segment", x = -72.89, xend = -72.86, y = 41.375, yend = 41.375, colour = "lightblue", size=.5)
pm_ct <- pm_ct + annotate("point", x = -72.89, y = 41.375, colour = "lightblue", size = 2)
pm_ct <- pm_ct + annotate("text", x = -72.845, y = 41.375, label = "Hamden", size=5, colour="gray30")
pm_ct <- pm_ct + annotate("point", x = -72.83, y = 41.375, colour="white", size=.2)
pm_ct <- pm_ct + theme(legend.key.size = unit(1, "cm"))
pm_ct

# labs(title=" (percent by tract)", fill="")
print(pm_ct)

ggsave(pm_ct, file = "img/stops_hamden_hispanic.png", width = 8, height = 6, type = "cairo-png")
# Black
pm_ct <- ggplot()
pm_ct <- pm_ct + geom_polygon(data = test_map, aes(x=long, y=lat, group=group, fill=black_p/100), color="white", size=.25)
pm_ct <- pm_ct + geom_polygon(data = test_borders, aes(x=long, y=lat, group=group), fill=NA, color = "black", size=0.5)
pm_ct <- pm_ct + coord_map()
pm_ct <- pm_ct + scale_fill_distiller(type="seq", trans="reverse", palette = "Reds", breaks=pretty_breaks(n=9), labels=percent, name="Stops")
pm_ct <- pm_ct + theme_nothing(legend=TRUE)
pm_ct <- pm_ct + labs(x=NULL, y=NULL, title=paste("Where black drivers are pulled over by", town_name, "police"))
#pm_ct <- pm_ct + theme_bw(base_family="Calibri")
#pm_ct <- pm_ct + theme(panel.grid.major=element_blank())
#pm_ct <- pm_ct + theme(panel.grid.minor=element_blank())
#pm_ct <- pm_ct + theme(panel.border=element_blank())
pm_ct <- pm_ct + theme(text = element_text(size=15))
#pm_ct <- pm_ct + theme(axis.ticks=element_blank())
#pm_ct <- pm_ct + theme(axis.text.x=element_blank())
pm_ct <- pm_ct + theme(plot.title=element_text(face="bold", hjust=.4))
pm_ct <- pm_ct + theme(plot.subtitle=element_text(face="italic", size=9, margin=margin(l=20)))
pm_ct <- pm_ct + theme(plot.caption=element_text(size=12, margin=margin(t=12), color="#7a7d7e", hjust=0))
#pm_ct <- pm_ct + scale_fill_gradient(low = "#b2b2b2", high = "tomato", labels = percent)
pm_ct <- pm_ct + annotate("segment", x = -73.07, xend = -73.05, y = 41.375, yend = 41.4, colour = "lightblue", size=.5)
pm_ct <- pm_ct + annotate("point", x = -73.07, y = 41.375, colour = "lightblue", size = 2)
pm_ct <- pm_ct + annotate("text", x = -73.033, y = 41.404, label = "Seymour", size=5, colour="gray30")
pm_ct <- pm_ct + annotate("segment", x = -72.93, xend = -72.87, y = 41.325, yend = 41.325, colour = "lightblue", size=.5)
pm_ct <- pm_ct + annotate("point", x = -72.93, y = 41.325, colour = "lightblue", size = 2)
pm_ct <- pm_ct + annotate("text", x = -72.85, y = 41.325, label = "New Haven", size=5, colour="gray30")
pm_ct <- pm_ct + annotate("segment", x = -72.89, xend = -72.86, y = 41.375, yend = 41.375, colour = "lightblue", size=.5)
pm_ct <- pm_ct + annotate("point", x = -72.89, y = 41.375, colour = "lightblue", size = 2)
pm_ct <- pm_ct + annotate("text", x = -72.845, y = 41.375, label = "Hamden", size=5, colour="gray30")
pm_ct <- pm_ct + annotate("point", x = -72.83, y = 41.375, colour="white", size=.2)
pm_ct <- pm_ct + theme(legend.key.size = unit(1, "cm"))
pm_ct

# labs(title=" (percent by tract)", fill="")
print(pm_ct)

ggsave(pm_ct, file = "img/stops_hamden_black.png", width = 8, height = 6, type = "cairo-png")
# Minorities
pm_ct <- ggplot()
pm_ct <- pm_ct + geom_polygon(data = test_map, aes(x=long, y=lat, group=group, fill=minority_p/100), color="white", size=.25)
pm_ct <- pm_ct + geom_polygon(data = test_borders, aes(x=long, y=lat, group=group), fill=NA, color = "black", size=0.5)
pm_ct <- pm_ct + coord_map()
pm_ct <- pm_ct + scale_fill_distiller(type="seq", trans="reverse", palette = "Reds", breaks=pretty_breaks(n=9), labels=percent, name="Stops")
pm_ct <- pm_ct + theme_nothing(legend=TRUE)
pm_ct <- pm_ct + labs(x=NULL, y=NULL, title=paste("Where minority drivers are pulled over by", town_name, "police"))
#pm_ct <- pm_ct + theme_bw(base_family="Calibri")
#pm_ct <- pm_ct + theme(panel.grid.major=element_blank())
#pm_ct <- pm_ct + theme(panel.grid.minor=element_blank())
#pm_ct <- pm_ct + theme(panel.border=element_blank())
pm_ct <- pm_ct + theme(text = element_text(size=15))
#pm_ct <- pm_ct + theme(axis.ticks=element_blank())
#pm_ct <- pm_ct + theme(axis.text.x=element_blank())
pm_ct <- pm_ct + theme(plot.title=element_text(face="bold", hjust=.4))
pm_ct <- pm_ct + theme(plot.subtitle=element_text(face="italic", size=9, margin=margin(l=20)))
pm_ct <- pm_ct + theme(plot.caption=element_text(size=12, margin=margin(t=12), color="#7a7d7e", hjust=0))
#pm_ct <- pm_ct + scale_fill_gradient(low = "#b2b2b2", high = "tomato", labels = percent)
pm_ct <- pm_ct + annotate("segment", x = -73.07, xend = -73.05, y = 41.375, yend = 41.4, colour = "lightblue", size=.5)
pm_ct <- pm_ct + annotate("point", x = -73.07, y = 41.375, colour = "lightblue", size = 2)
pm_ct <- pm_ct + annotate("text", x = -73.033, y = 41.404, label = "Seymour", size=5, colour="gray30")
pm_ct <- pm_ct + annotate("segment", x = -72.93, xend = -72.87, y = 41.325, yend = 41.325, colour = "lightblue", size=.5)
pm_ct <- pm_ct + annotate("point", x = -72.93, y = 41.325, colour = "lightblue", size = 2)
pm_ct <- pm_ct + annotate("text", x = -72.85, y = 41.325, label = "New Haven", size=5, colour="gray30")
pm_ct <- pm_ct + annotate("segment", x = -72.89, xend = -72.86, y = 41.375, yend = 41.375, colour = "lightblue", size=.5)
pm_ct <- pm_ct + annotate("point", x = -72.89, y = 41.375, colour = "lightblue", size = 2)
pm_ct <- pm_ct + annotate("text", x = -72.845, y = 41.375, label = "Hamden", size=5, colour="gray30")
pm_ct <- pm_ct + annotate("point", x = -72.83, y = 41.375, colour="white", size=.2)
pm_ct <- pm_ct + theme(legend.key.size = unit(1, "cm"))
pm_ct

# labs(title=" (percent by tract)", fill="")
print(pm_ct)

ggsave(pm_ct, file = "img/stops_hamden_minorities.png", width = 8, height = 6, type = "cairo-png")
# White
pm_ct <- ggplot()
pm_ct <- pm_ct + geom_polygon(data = test_map, aes(x=long, y=lat, group=group, fill=white_p/100), color="white", size=.25)
pm_ct <- pm_ct + geom_polygon(data = test_borders, aes(x=long, y=lat, group=group), fill=NA, color = "black", size=0.5)
pm_ct <- pm_ct + coord_map()
pm_ct <- pm_ct + scale_fill_distiller(type="seq", trans="reverse", palette = "Reds", breaks=pretty_breaks(n=9), labels=percent, name="Stops")
pm_ct <- pm_ct + theme_nothing(legend=TRUE)
pm_ct <- pm_ct + labs(x=NULL, y=NULL, title=paste("Where white drivers are pulled over by", town_name, "police"))
#pm_ct <- pm_ct + theme_bw(base_family="Calibri")
#pm_ct <- pm_ct + theme(panel.grid.major=element_blank())
#pm_ct <- pm_ct + theme(panel.grid.minor=element_blank())
#pm_ct <- pm_ct + theme(panel.border=element_blank())
pm_ct <- pm_ct + theme(text = element_text(size=15))
#pm_ct <- pm_ct + theme(axis.ticks=element_blank())
#pm_ct <- pm_ct + theme(axis.text.x=element_blank())
pm_ct <- pm_ct + theme(plot.title=element_text(face="bold", hjust=.4))
pm_ct <- pm_ct + theme(plot.subtitle=element_text(face="italic", size=9, margin=margin(l=20)))
pm_ct <- pm_ct + theme(plot.caption=element_text(size=12, margin=margin(t=12), color="#7a7d7e", hjust=0))
#pm_ct <- pm_ct + scale_fill_gradient(low = "#b2b2b2", high = "tomato", labels = percent)
pm_ct <- pm_ct + annotate("segment", x = -73.07, xend = -73.05, y = 41.375, yend = 41.4, colour = "lightblue", size=.5)
pm_ct <- pm_ct + annotate("point", x = -73.07, y = 41.375, colour = "lightblue", size = 2)
pm_ct <- pm_ct + annotate("text", x = -73.033, y = 41.404, label = "Seymour", size=5, colour="gray30")
pm_ct <- pm_ct + annotate("segment", x = -72.93, xend = -72.87, y = 41.325, yend = 41.325, colour = "lightblue", size=.5)
pm_ct <- pm_ct + annotate("point", x = -72.93, y = 41.325, colour = "lightblue", size = 2)
pm_ct <- pm_ct + annotate("text", x = -72.85, y = 41.325, label = "New Haven", size=5, colour="gray30")
pm_ct <- pm_ct + annotate("segment", x = -72.89, xend = -72.86, y = 41.375, yend = 41.375, colour = "lightblue", size=.5)
pm_ct <- pm_ct + annotate("point", x = -72.89, y = 41.375, colour = "lightblue", size = 2)
pm_ct <- pm_ct + annotate("text", x = -72.845, y = 41.375, label = "Hamden", size=5, colour="gray30")
pm_ct <- pm_ct + annotate("point", x = -72.83, y = 41.375, colour="white", size=.2)
pm_ct <- pm_ct + theme(legend.key.size = unit(1, "cm"))
pm_ct

# labs(title=" (percent by tract)", fill="")
print(pm_ct)

ggsave(pm_ct, file = "img/stops_hamden_white.png", width = 8, height = 6, type = "cairo-png")
town_name <- "Manchester"
#test_map <- subset(total_map, town_department==town_name)
test_map <- subset(total_map, town_department=="Manchester")
test_map <- subset(test_map, !is.na(white_p))
test_borders <- subset(townborders, id==town_name)
# Hispanic
pm_ct <- ggplot()
pm_ct <- pm_ct + geom_polygon(data = test_map, aes(x=long, y=lat, group=group, fill=hispanic_p/100), color="white", size=.25)
pm_ct <- pm_ct + geom_polygon(data = test_borders, aes(x=long, y=lat, group=group), fill=NA, color = "black", size=0.5)
pm_ct <- pm_ct + coord_map()
pm_ct <- pm_ct + scale_fill_distiller(type="seq", trans="reverse", palette = "Reds", breaks=pretty_breaks(n=9), labels=percent, name="Stops")
pm_ct <- pm_ct + theme_nothing(legend=TRUE)
pm_ct <- pm_ct + labs(x=NULL, y=NULL, title=paste("Where Hispanic drivers are pulled over by", town_name, "police"))
#pm_ct <- pm_ct + theme_bw(base_family="Calibri")
#pm_ct <- pm_ct + theme(panel.grid.major=element_blank())
#pm_ct <- pm_ct + theme(panel.grid.minor=element_blank())
#pm_ct <- pm_ct + theme(panel.border=element_blank())
pm_ct <- pm_ct + theme(text = element_text(size=15))
#pm_ct <- pm_ct + theme(axis.ticks=element_blank())
#pm_ct <- pm_ct + theme(axis.text.x=element_blank())
pm_ct <- pm_ct + theme(plot.title=element_text(face="bold", hjust=.4))
pm_ct <- pm_ct + theme(plot.subtitle=element_text(face="italic", size=9, margin=margin(l=20)))
pm_ct <- pm_ct + theme(plot.caption=element_text(size=12, margin=margin(t=12), color="#7a7d7e", hjust=0))
#pm_ct <- pm_ct + scale_fill_gradient(low = "#b2b2b2", high = "tomato", labels = percent)
pm_ct <- pm_ct + theme(legend.key.size = unit(1, "cm"))
pm_ct

# labs(title=" (percent by tract)", fill="")
print(pm_ct)

ggsave(pm_ct, file = "img/stops_manchester_hispanic.png", width = 8, height = 6, type = "cairo-png")
# Black
pm_ct <- ggplot()
pm_ct <- pm_ct + geom_polygon(data = test_map, aes(x=long, y=lat, group=group, fill=black_p/100), color="white", size=.25)
pm_ct <- pm_ct + geom_polygon(data = test_borders, aes(x=long, y=lat, group=group), fill=NA, color = "black", size=0.5)
pm_ct <- pm_ct + coord_map()
pm_ct <- pm_ct + scale_fill_distiller(type="seq", trans="reverse", palette = "Reds", breaks=pretty_breaks(n=9), labels=percent, name="Stops")
pm_ct <- pm_ct + theme_nothing(legend=TRUE)
pm_ct <- pm_ct + labs(x=NULL, y=NULL, title=paste("Where black drivers are pulled over by", town_name, "police"))
#pm_ct <- pm_ct + theme_bw(base_family="Calibri")
#pm_ct <- pm_ct + theme(panel.grid.major=element_blank())
#pm_ct <- pm_ct + theme(panel.grid.minor=element_blank())
#pm_ct <- pm_ct + theme(panel.border=element_blank())
pm_ct <- pm_ct + theme(text = element_text(size=15))
#pm_ct <- pm_ct + theme(axis.ticks=element_blank())
#pm_ct <- pm_ct + theme(axis.text.x=element_blank())
pm_ct <- pm_ct + theme(plot.title=element_text(face="bold", hjust=.4))
pm_ct <- pm_ct + theme(plot.subtitle=element_text(face="italic", size=9, margin=margin(l=20)))
pm_ct <- pm_ct + theme(plot.caption=element_text(size=12, margin=margin(t=12), color="#7a7d7e", hjust=0))
#pm_ct <- pm_ct + scale_fill_gradient(low = "#b2b2b2", high = "tomato", labels = percent)
pm_ct <- pm_ct + theme(legend.key.size = unit(1, "cm"))
pm_ct

# labs(title=" (percent by tract)", fill="")
print(pm_ct)

ggsave(pm_ct, file = "img/stops_manchester_black.png", width = 8, height = 6, type = "cairo-png")
# Minorities
pm_ct <- ggplot()
pm_ct <- pm_ct + geom_polygon(data = test_map, aes(x=long, y=lat, group=group, fill=minority_p/100), color="white", size=.25)
pm_ct <- pm_ct + geom_polygon(data = test_borders, aes(x=long, y=lat, group=group), fill=NA, color = "black", size=0.5)
pm_ct <- pm_ct + coord_map()
pm_ct <- pm_ct + scale_fill_distiller(type="seq", trans="reverse", palette = "Reds", breaks=pretty_breaks(n=9), labels=percent, name="Stops")
pm_ct <- pm_ct + theme_nothing(legend=TRUE)
pm_ct <- pm_ct + labs(x=NULL, y=NULL, title=paste("Where minority drivers are pulled over by", town_name, "police"))
#pm_ct <- pm_ct + theme_bw(base_family="Calibri")
#pm_ct <- pm_ct + theme(panel.grid.major=element_blank())
#pm_ct <- pm_ct + theme(panel.grid.minor=element_blank())
#pm_ct <- pm_ct + theme(panel.border=element_blank())
pm_ct <- pm_ct + theme(text = element_text(size=15))
#pm_ct <- pm_ct + theme(axis.ticks=element_blank())
#pm_ct <- pm_ct + theme(axis.text.x=element_blank())
pm_ct <- pm_ct + theme(plot.title=element_text(face="bold", hjust=.4))
pm_ct <- pm_ct + theme(plot.subtitle=element_text(face="italic", size=9, margin=margin(l=20)))
pm_ct <- pm_ct + theme(plot.caption=element_text(size=12, margin=margin(t=12), color="#7a7d7e", hjust=0))
#pm_ct <- pm_ct + scale_fill_gradient(low = "#b2b2b2", high = "tomato", labels = percent)
pm_ct <- pm_ct + theme(legend.key.size = unit(1, "cm"))
pm_ct

# labs(title=" (percent by tract)", fill="")
print(pm_ct)

ggsave(pm_ct, file = "img/stops_manchester_minorities.png", width = 8, height = 6, type = "cairo-png")
# White
pm_ct <- ggplot()
pm_ct <- pm_ct + geom_polygon(data = test_map, aes(x=long, y=lat, group=group, fill=white_p/100), color="white", size=.25)
pm_ct <- pm_ct + geom_polygon(data = test_borders, aes(x=long, y=lat, group=group), fill=NA, color = "black", size=0.5)
pm_ct <- pm_ct + coord_map()
pm_ct <- pm_ct + scale_fill_distiller(type="seq", trans="reverse", palette = "Reds", breaks=pretty_breaks(n=9), labels=percent, name="Stops")
pm_ct <- pm_ct + theme_nothing(legend=TRUE)
pm_ct <- pm_ct + labs(x=NULL, y=NULL, title=paste("Where white drivers are pulled over by", town_name, "police"))
#pm_ct <- pm_ct + theme_bw(base_family="Calibri")
#pm_ct <- pm_ct + theme(panel.grid.major=element_blank())
#pm_ct <- pm_ct + theme(panel.grid.minor=element_blank())
#pm_ct <- pm_ct + theme(panel.border=element_blank())
pm_ct <- pm_ct + theme(text = element_text(size=15))
#pm_ct <- pm_ct + theme(axis.ticks=element_blank())
#pm_ct <- pm_ct + theme(axis.text.x=element_blank())
pm_ct <- pm_ct + theme(plot.title=element_text(face="bold", hjust=.4))
pm_ct <- pm_ct + theme(plot.subtitle=element_text(face="italic", size=9, margin=margin(l=20)))
pm_ct <- pm_ct + theme(plot.caption=element_text(size=12, margin=margin(t=12), color="#7a7d7e", hjust=0))
#pm_ct <- pm_ct + scale_fill_gradient(low = "#b2b2b2", high = "tomato", labels = percent)
pm_ct <- pm_ct + theme(legend.key.size = unit(1, "cm"))
pm_ct

# labs(title=" (percent by tract)", fill="")
print(pm_ct)

ggsave(pm_ct, file = "img/stops_manchester_white.png", width = 8, height = 6, type = "cairo-png")
town_name <- "New Britain"
#test_map <- subset(total_map, town_department==town_name)
test_map <- subset(total_map, town_department=="New Britain")
test_map <- subset(test_map, !is.na(white_p))
test_borders <- subset(townborders, id==town_name)
# Hispanic
pm_ct <- ggplot()
pm_ct <- pm_ct + geom_polygon(data = test_map, aes(x=long, y=lat, group=group, fill=hispanic_p/100), color="white", size=.25)
pm_ct <- pm_ct + geom_polygon(data = test_borders, aes(x=long, y=lat, group=group), fill=NA, color = "black", size=0.5)
pm_ct <- pm_ct + coord_map()
pm_ct <- pm_ct + scale_fill_distiller(type="seq", trans="reverse", palette = "Reds", breaks=pretty_breaks(n=9), labels=percent, name="Stops")
pm_ct <- pm_ct + theme_nothing(legend=TRUE)
pm_ct <- pm_ct + labs(x=NULL, y=NULL, title=paste("Where Hispanic drivers are pulled over by", town_name, "police"))
#pm_ct <- pm_ct + theme_bw(base_family="Calibri")
#pm_ct <- pm_ct + theme(panel.grid.major=element_blank())
#pm_ct <- pm_ct + theme(panel.grid.minor=element_blank())
#pm_ct <- pm_ct + theme(panel.border=element_blank())
pm_ct <- pm_ct + theme(text = element_text(size=15))
#pm_ct <- pm_ct + theme(axis.ticks=element_blank())
#pm_ct <- pm_ct + theme(axis.text.x=element_blank())
pm_ct <- pm_ct + theme(plot.title=element_text(face="bold", hjust=.4))
pm_ct <- pm_ct + theme(plot.subtitle=element_text(face="italic", size=9, margin=margin(l=20)))
pm_ct <- pm_ct + theme(plot.caption=element_text(size=12, margin=margin(t=12), color="#7a7d7e", hjust=0))
#pm_ct <- pm_ct + scale_fill_gradient(low = "#b2b2b2", high = "tomato", labels = percent)
pm_ct <- pm_ct + annotate("segment", x = -72.82, xend = -72.785, y = 41.73, yend = 41.73, colour = "lightblue", size=.5)
pm_ct <- pm_ct + annotate("point", x = -72.82, y = 41.73, colour = "lightblue", size = 2)
pm_ct <- pm_ct + annotate("text", x = -72.768, y = 41.73, label = "Farmington", size=5, colour="gray30")
pm_ct <- pm_ct + theme(legend.key.size = unit(1, "cm"))
pm_ct

# labs(title=" (percent by tract)", fill="")
print(pm_ct)

ggsave(pm_ct, file = "img/stops_newbritain_hispanic.png", width = 8, height = 6, type = "cairo-png")
# Black
pm_ct <- ggplot()
pm_ct <- pm_ct + geom_polygon(data = test_map, aes(x=long, y=lat, group=group, fill=black_p/100), color="white", size=.25)
pm_ct <- pm_ct + geom_polygon(data = test_borders, aes(x=long, y=lat, group=group), fill=NA, color = "black", size=0.5)
pm_ct <- pm_ct + coord_map()
pm_ct <- pm_ct + scale_fill_distiller(type="seq", trans="reverse", palette = "Reds", breaks=pretty_breaks(n=9), labels=percent, name="Stops")
pm_ct <- pm_ct + theme_nothing(legend=TRUE)
pm_ct <- pm_ct + labs(x=NULL, y=NULL, title=paste("Where black drivers are pulled over by", town_name, "police"))
#pm_ct <- pm_ct + theme_bw(base_family="Calibri")
#pm_ct <- pm_ct + theme(panel.grid.major=element_blank())
#pm_ct <- pm_ct + theme(panel.grid.minor=element_blank())
#pm_ct <- pm_ct + theme(panel.border=element_blank())
pm_ct <- pm_ct + theme(text = element_text(size=15))
#pm_ct <- pm_ct + theme(axis.ticks=element_blank())
#pm_ct <- pm_ct + theme(axis.text.x=element_blank())
pm_ct <- pm_ct + theme(plot.title=element_text(face="bold", hjust=.4))
pm_ct <- pm_ct + theme(plot.subtitle=element_text(face="italic", size=9, margin=margin(l=20)))
pm_ct <- pm_ct + theme(plot.caption=element_text(size=12, margin=margin(t=12), color="#7a7d7e", hjust=0))
#pm_ct <- pm_ct + scale_fill_gradient(low = "#b2b2b2", high = "tomato", labels = percent)
pm_ct <- pm_ct + annotate("segment", x = -72.82, xend = -72.785, y = 41.73, yend = 41.73, colour = "lightblue", size=.5)
pm_ct <- pm_ct + annotate("point", x = -72.82, y = 41.73, colour = "lightblue", size = 2)
pm_ct <- pm_ct + annotate("text", x = -72.768, y = 41.73, label = "Farmington", size=5, colour="gray30")
pm_ct <- pm_ct + theme(legend.key.size = unit(1, "cm"))
pm_ct

# labs(title=" (percent by tract)", fill="")
print(pm_ct)

ggsave(pm_ct, file = "img/stops_newbritain_black.png", width = 8, height = 6, type = "cairo-png")
# Minorities
pm_ct <- ggplot()
pm_ct <- pm_ct + geom_polygon(data = test_map, aes(x=long, y=lat, group=group, fill=minority_p/100), color="white", size=.25)
pm_ct <- pm_ct + geom_polygon(data = test_borders, aes(x=long, y=lat, group=group), fill=NA, color = "black", size=0.5)
pm_ct <- pm_ct + coord_map()
pm_ct <- pm_ct + scale_fill_distiller(type="seq", trans="reverse", palette = "Reds", breaks=pretty_breaks(n=9), labels=percent, name="Stops")
pm_ct <- pm_ct + theme_nothing(legend=TRUE)
pm_ct <- pm_ct + labs(x=NULL, y=NULL, title=paste("Where minority drivers are pulled over by", town_name, "police"))
#pm_ct <- pm_ct + theme_bw(base_family="Calibri")
#pm_ct <- pm_ct + theme(panel.grid.major=element_blank())
#pm_ct <- pm_ct + theme(panel.grid.minor=element_blank())
#pm_ct <- pm_ct + theme(panel.border=element_blank())
pm_ct <- pm_ct + theme(text = element_text(size=15))
#pm_ct <- pm_ct + theme(axis.ticks=element_blank())
#pm_ct <- pm_ct + theme(axis.text.x=element_blank())
pm_ct <- pm_ct + theme(plot.title=element_text(face="bold", hjust=.4))
pm_ct <- pm_ct + theme(plot.subtitle=element_text(face="italic", size=9, margin=margin(l=20)))
pm_ct <- pm_ct + theme(plot.caption=element_text(size=12, margin=margin(t=12), color="#7a7d7e", hjust=0))
#pm_ct <- pm_ct + scale_fill_gradient(low = "#b2b2b2", high = "tomato", labels = percent)
pm_ct <- pm_ct + annotate("segment", x = -72.82, xend = -72.785, y = 41.73, yend = 41.73, colour = "lightblue", size=.5)
pm_ct <- pm_ct + annotate("point", x = -72.82, y = 41.73, colour = "lightblue", size = 2)
pm_ct <- pm_ct + annotate("text", x = -72.768, y = 41.73, label = "Farmington", size=5, colour="gray30")
pm_ct <- pm_ct + theme(legend.key.size = unit(1, "cm"))
pm_ct

# labs(title=" (percent by tract)", fill="")
print(pm_ct)

ggsave(pm_ct, file = "img/stops_newbritain_minorities.png", width = 8, height = 6, type = "cairo-png")
# White
pm_ct <- ggplot()
pm_ct <- pm_ct + geom_polygon(data = test_map, aes(x=long, y=lat, group=group, fill=white_p/100), color="white", size=.25)
pm_ct <- pm_ct + geom_polygon(data = test_borders, aes(x=long, y=lat, group=group), fill=NA, color = "black", size=0.5)
pm_ct <- pm_ct + coord_map()
pm_ct <- pm_ct + scale_fill_distiller(type="seq", trans="reverse", palette = "Reds", breaks=pretty_breaks(n=9), labels=percent, name="Stops")
pm_ct <- pm_ct + theme_nothing(legend=TRUE)
pm_ct <- pm_ct + labs(x=NULL, y=NULL, title=paste("Where white drivers are pulled over by", town_name, "police"))
#pm_ct <- pm_ct + theme_bw(base_family="Calibri")
#pm_ct <- pm_ct + theme(panel.grid.major=element_blank())
#pm_ct <- pm_ct + theme(panel.grid.minor=element_blank())
#pm_ct <- pm_ct + theme(panel.border=element_blank())
pm_ct <- pm_ct + theme(text = element_text(size=15))
#pm_ct <- pm_ct + theme(axis.ticks=element_blank())
#pm_ct <- pm_ct + theme(axis.text.x=element_blank())
pm_ct <- pm_ct + theme(plot.title=element_text(face="bold", hjust=.4))
pm_ct <- pm_ct + theme(plot.subtitle=element_text(face="italic", size=9, margin=margin(l=20)))
pm_ct <- pm_ct + theme(plot.caption=element_text(size=12, margin=margin(t=12), color="#7a7d7e", hjust=0))
#pm_ct <- pm_ct + scale_fill_gradient(low = "#b2b2b2", high = "tomato", labels = percent)
pm_ct <- pm_ct + annotate("segment", x = -72.82, xend = -72.785, y = 41.73, yend = 41.73, colour = "lightblue", size=.5)
pm_ct <- pm_ct + annotate("point", x = -72.82, y = 41.73, colour = "lightblue", size = 2)
pm_ct <- pm_ct + annotate("text", x = -72.768, y = 41.73, label = "Farmington", size=5, colour="gray30")
pm_ct <- pm_ct + theme(legend.key.size = unit(1, "cm"))
pm_ct

# labs(title=" (percent by tract)", fill="")
print(pm_ct)

ggsave(pm_ct, file = "img/stops_newbritain_white.png", width = 8, height = 6, type = "cairo-png")
town_name <- "Stratford"
#test_map <- subset(total_map, town_department==town_name)
test_map <- subset(total_map, town_department=="Stratford")
test_map <- subset(test_map, !is.na(white_p))
test_borders <- subset(townborders, id==town_name)
# Hispanic
pm_ct <- ggplot()
pm_ct <- pm_ct + geom_polygon(data = test_map, aes(x=long, y=lat, group=group, fill=hispanic_p/100), color="white", size=.25)
pm_ct <- pm_ct + geom_polygon(data = test_borders, aes(x=long, y=lat, group=group), fill=NA, color = "black", size=0.5)
pm_ct <- pm_ct + coord_map()
pm_ct <- pm_ct + scale_fill_distiller(type="seq", trans="reverse", palette = "Reds", breaks=pretty_breaks(n=9), labels=percent, name="Stops")
pm_ct <- pm_ct + theme_nothing(legend=TRUE)
pm_ct <- pm_ct + labs(x=NULL, y=NULL, title=paste("Where Hispanic drivers are pulled over by", town_name, "police"))
#pm_ct <- pm_ct + theme_bw(base_family="Calibri")
#pm_ct <- pm_ct + theme(panel.grid.major=element_blank())
#pm_ct <- pm_ct + theme(panel.grid.minor=element_blank())
#pm_ct <- pm_ct + theme(panel.border=element_blank())
pm_ct <- pm_ct + theme(text = element_text(size=15))
#pm_ct <- pm_ct + theme(axis.ticks=element_blank())
#pm_ct <- pm_ct + theme(axis.text.x=element_blank())
pm_ct <- pm_ct + theme(plot.title=element_text(face="bold", hjust=.4))
pm_ct <- pm_ct + theme(plot.subtitle=element_text(face="italic", size=9, margin=margin(l=20)))
pm_ct <- pm_ct + theme(plot.caption=element_text(size=12, margin=margin(t=12), color="#7a7d7e", hjust=0))
#pm_ct <- pm_ct + scale_fill_gradient(low = "#b2b2b2", high = "tomato", labels = percent)
pm_ct <- pm_ct + annotate("segment", x = -73.17, xend = -73.20, y = 41.24, yend = 41.24, colour = "lightblue", size=.5)
pm_ct <- pm_ct + annotate("point", x = -73.17, y = 41.24, colour = "lightblue", size = 2)
pm_ct <- pm_ct + annotate("text", x = -73.215, y = 41.24, label = " Trumbull", size=5, colour="gray30")
pm_ct <- pm_ct + annotate("segment", x = -73.16, xend = -73.19, y = 41.19, yend = 41.19, colour = "lightblue", size=.5)
pm_ct <- pm_ct + annotate("point", x = -73.16, y = 41.19, colour = "lightblue", size = 2)
pm_ct <- pm_ct + annotate("text", x = -73.205, y = 41.19, label = "Bridgeport", size=5, colour="gray30")
pm_ct <- pm_ct + annotate("point", x = -73.22, y = 41.19, colour="white", size=.2)
pm_ct <- pm_ct + theme(legend.key.size = unit(1, "cm"))
pm_ct

# labs(title=" (percent by tract)", fill="")
print(pm_ct)

ggsave(pm_ct, file = "img/stops_stratford_hispanic.png", width = 8, height = 6, type = "cairo-png")
# Black
pm_ct <- ggplot()
pm_ct <- pm_ct + geom_polygon(data = test_map, aes(x=long, y=lat, group=group, fill=black_p/100), color="white", size=.25)
pm_ct <- pm_ct + geom_polygon(data = test_borders, aes(x=long, y=lat, group=group), fill=NA, color = "black", size=0.5)
pm_ct <- pm_ct + coord_map()
pm_ct <- pm_ct + scale_fill_distiller(type="seq", trans="reverse", palette = "Reds", breaks=pretty_breaks(n=9), labels=percent, name="Stops")
pm_ct <- pm_ct + theme_nothing(legend=TRUE)
pm_ct <- pm_ct + labs(x=NULL, y=NULL, title=paste("Where black drivers are pulled over by", town_name, "police"))
#pm_ct <- pm_ct + theme_bw(base_family="Calibri")
#pm_ct <- pm_ct + theme(panel.grid.major=element_blank())
#pm_ct <- pm_ct + theme(panel.grid.minor=element_blank())
#pm_ct <- pm_ct + theme(panel.border=element_blank())
pm_ct <- pm_ct + theme(text = element_text(size=15))
#pm_ct <- pm_ct + theme(axis.ticks=element_blank())
#pm_ct <- pm_ct + theme(axis.text.x=element_blank())
pm_ct <- pm_ct + theme(plot.title=element_text(face="bold", hjust=.4))
pm_ct <- pm_ct + theme(plot.subtitle=element_text(face="italic", size=9, margin=margin(l=20)))
pm_ct <- pm_ct + theme(plot.caption=element_text(size=12, margin=margin(t=12), color="#7a7d7e", hjust=0))
#pm_ct <- pm_ct + scale_fill_gradient(low = "#b2b2b2", high = "tomato", labels = percent)
pm_ct <- pm_ct + annotate("segment", x = -73.17, xend = -73.20, y = 41.24, yend = 41.24, colour = "lightblue", size=.5)
pm_ct <- pm_ct + annotate("point", x = -73.17, y = 41.24, colour = "lightblue", size = 2)
pm_ct <- pm_ct + annotate("text", x = -73.215, y = 41.24, label = " Trumbull", size=5, colour="gray30")
pm_ct <- pm_ct + annotate("segment", x = -73.16, xend = -73.19, y = 41.19, yend = 41.19, colour = "lightblue", size=.5)
pm_ct <- pm_ct + annotate("point", x = -73.16, y = 41.19, colour = "lightblue", size = 2)
pm_ct <- pm_ct + annotate("text", x = -73.205, y = 41.19, label = "Bridgeport", size=5, colour="gray30")
pm_ct <- pm_ct + annotate("point", x = -73.22, y = 41.19, colour="white", size=.2)
pm_ct <- pm_ct + theme(legend.key.size = unit(1, "cm"))
pm_ct

# labs(title=" (percent by tract)", fill="")
print(pm_ct)

ggsave(pm_ct, file = "img/stops_stratford_black.png", width = 8, height = 6, type = "cairo-png")
# Minorities
pm_ct <- ggplot()
pm_ct <- pm_ct + geom_polygon(data = test_map, aes(x=long, y=lat, group=group, fill=minority_p/100), color="white", size=.25)
pm_ct <- pm_ct + geom_polygon(data = test_borders, aes(x=long, y=lat, group=group), fill=NA, color = "black", size=0.5)
pm_ct <- pm_ct + coord_map()
pm_ct <- pm_ct + scale_fill_distiller(type="seq", trans="reverse", palette = "Reds", breaks=pretty_breaks(n=9), labels=percent, name="Stops")
pm_ct <- pm_ct + theme_nothing(legend=TRUE)
pm_ct <- pm_ct + labs(x=NULL, y=NULL, title=paste("Where minority drivers are pulled over by", town_name, "police"))
#pm_ct <- pm_ct + theme_bw(base_family="Calibri")
#pm_ct <- pm_ct + theme(panel.grid.major=element_blank())
#pm_ct <- pm_ct + theme(panel.grid.minor=element_blank())
#pm_ct <- pm_ct + theme(panel.border=element_blank())
pm_ct <- pm_ct + theme(text = element_text(size=15))
#pm_ct <- pm_ct + theme(axis.ticks=element_blank())
#pm_ct <- pm_ct + theme(axis.text.x=element_blank())
pm_ct <- pm_ct + theme(plot.title=element_text(face="bold", hjust=.4))
pm_ct <- pm_ct + theme(plot.subtitle=element_text(face="italic", size=9, margin=margin(l=20)))
pm_ct <- pm_ct + theme(plot.caption=element_text(size=12, margin=margin(t=12), color="#7a7d7e", hjust=0))
#pm_ct <- pm_ct + scale_fill_gradient(low = "#b2b2b2", high = "tomato", labels = percent)
pm_ct <- pm_ct + annotate("segment", x = -73.17, xend = -73.20, y = 41.24, yend = 41.24, colour = "lightblue", size=.5)
pm_ct <- pm_ct + annotate("point", x = -73.17, y = 41.24, colour = "lightblue", size = 2)
pm_ct <- pm_ct + annotate("text", x = -73.215, y = 41.24, label = " Trumbull", size=5, colour="gray30")
pm_ct <- pm_ct + annotate("segment", x = -73.16, xend = -73.19, y = 41.19, yend = 41.19, colour = "lightblue", size=.5)
pm_ct <- pm_ct + annotate("point", x = -73.16, y = 41.19, colour = "lightblue", size = 2)
pm_ct <- pm_ct + annotate("text", x = -73.205, y = 41.19, label = "Bridgeport", size=5, colour="gray30")
pm_ct <- pm_ct + annotate("point", x = -73.22, y = 41.19, colour="white", size=.2)
pm_ct <- pm_ct + theme(legend.key.size = unit(1, "cm"))
pm_ct

# labs(title=" (percent by tract)", fill="")
print(pm_ct)

ggsave(pm_ct, file = "img/stops_stratford_minorities.png", width = 8, height = 6, type = "cairo-png")
# White
pm_ct <- ggplot()
pm_ct <- pm_ct + geom_polygon(data = test_map, aes(x=long, y=lat, group=group, fill=white_p/100), color="white", size=.25)
pm_ct <- pm_ct + geom_polygon(data = test_borders, aes(x=long, y=lat, group=group), fill=NA, color = "black", size=0.5)
pm_ct <- pm_ct + coord_map()
pm_ct <- pm_ct + scale_fill_distiller(type="seq", trans="reverse", palette = "Reds", breaks=pretty_breaks(n=9), labels=percent, name="Stops")
pm_ct <- pm_ct + theme_nothing(legend=TRUE)
pm_ct <- pm_ct + labs(x=NULL, y=NULL, title=paste("Where white drivers are pulled over by", town_name, "police"))
#pm_ct <- pm_ct + theme_bw(base_family="Calibri")
#pm_ct <- pm_ct + theme(panel.grid.major=element_blank())
#pm_ct <- pm_ct + theme(panel.grid.minor=element_blank())
#pm_ct <- pm_ct + theme(panel.border=element_blank())
pm_ct <- pm_ct + theme(text = element_text(size=15))
#pm_ct <- pm_ct + theme(axis.ticks=element_blank())
#pm_ct <- pm_ct + theme(axis.text.x=element_blank())
pm_ct <- pm_ct + theme(plot.title=element_text(face="bold", hjust=.4))
pm_ct <- pm_ct + theme(plot.subtitle=element_text(face="italic", size=9, margin=margin(l=20)))
pm_ct <- pm_ct + theme(plot.caption=element_text(size=12, margin=margin(t=12), color="#7a7d7e", hjust=0))
#pm_ct <- pm_ct + scale_fill_gradient(low = "#b2b2b2", high = "tomato", labels = percent)
pm_ct <- pm_ct + annotate("segment", x = -73.17, xend = -73.20, y = 41.24, yend = 41.24, colour = "lightblue", size=.5)
pm_ct <- pm_ct + annotate("point", x = -73.17, y = 41.24, colour = "lightblue", size = 2)
pm_ct <- pm_ct + annotate("text", x = -73.215, y = 41.24, label = " Trumbull", size=5, colour="gray30")
pm_ct <- pm_ct + annotate("segment", x = -73.16, xend = -73.19, y = 41.19, yend = 41.19, colour = "lightblue", size=.5)
pm_ct <- pm_ct + annotate("point", x = -73.16, y = 41.19, colour = "lightblue", size = 2)
pm_ct <- pm_ct + annotate("text", x = -73.205, y = 41.19, label = "Bridgeport", size=5, colour="gray30")
pm_ct <- pm_ct + annotate("point", x = -73.22, y = 41.19, colour="white", size=.2)
pm_ct <- pm_ct + theme(legend.key.size = unit(1, "cm"))
pm_ct

# labs(title=" (percent by tract)", fill="")
print(pm_ct)

ggsave(pm_ct, file = "img/stops_stratford_white.png", width = 8, height = 6, type = "cairo-png")
town_name <- "Waterbury"
#test_map <- subset(total_map, town_department==town_name)
test_map <- subset(total_map, town_department=="Waterbury")
test_map <- subset(test_map, !is.na(white_p))
test_borders <- subset(townborders, id==town_name)
# Hispanic
pm_ct <- ggplot()
pm_ct <- pm_ct + geom_polygon(data = test_map, aes(x=long, y=lat, group=group, fill=hispanic_p/100), color="white", size=.25)
pm_ct <- pm_ct + geom_polygon(data = test_borders, aes(x=long, y=lat, group=group), fill=NA, color = "black", size=0.5)
pm_ct <- pm_ct + coord_map()
pm_ct <- pm_ct + scale_fill_distiller(type="seq", trans="reverse", palette = "Reds", breaks=pretty_breaks(n=9), labels=percent, name="Stops")
pm_ct <- pm_ct + theme_nothing(legend=TRUE)
pm_ct <- pm_ct + labs(x=NULL, y=NULL, title=paste("Where Hispanic drivers are pulled over by", town_name, "police"))
#pm_ct <- pm_ct + theme_bw(base_family="Calibri")
#pm_ct <- pm_ct + theme(panel.grid.major=element_blank())
#pm_ct <- pm_ct + theme(panel.grid.minor=element_blank())
#pm_ct <- pm_ct + theme(panel.border=element_blank())
pm_ct <- pm_ct + theme(text = element_text(size=15))
#pm_ct <- pm_ct + theme(axis.ticks=element_blank())
#pm_ct <- pm_ct + theme(axis.text.x=element_blank())
pm_ct <- pm_ct + theme(plot.title=element_text(face="bold", hjust=.4))
pm_ct <- pm_ct + theme(plot.subtitle=element_text(face="italic", size=9, margin=margin(l=20)))
pm_ct <- pm_ct + theme(plot.caption=element_text(size=12, margin=margin(t=12), color="#7a7d7e", hjust=0))
#pm_ct <- pm_ct + scale_fill_gradient(low = "#b2b2b2", high = "tomato", labels = percent)
pm_ct <- pm_ct + annotate("segment", x = -73.1, xend = -73.06, y = 41.64, yend = 41.64, colour = "lightblue", size=.5)
pm_ct <- pm_ct + annotate("point", x = -73.1, y = 41.64, colour = "lightblue", size = 2)
pm_ct <- pm_ct + annotate("text", x = -73.04, y = 41.64, label = "Watertown", size=5, colour="gray30")
pm_ct <- pm_ct + annotate("segment", x = -72.97, xend = -72.93, y = 41.57, yend = 41.57, colour = "lightblue", size=.5)
pm_ct <- pm_ct + annotate("point", x = -72.97, y = 41.57, colour = "lightblue", size = 2)
pm_ct <- pm_ct + annotate("text", x = -72.915, y = 41.57, label = "Wolcott", size=5, colour="gray30")
pm_ct <- pm_ct + annotate("point", x = -72.9, y = 41.57, colour="white", size=.2)
pm_ct <- pm_ct + theme(legend.key.size = unit(1, "cm"))
pm_ct

# labs(title=" (percent by tract)", fill="")
print(pm_ct)

ggsave(pm_ct, file = "img/stops_waterbury_hispanic.png", width = 8, height = 6, type = "cairo-png")
# Black
pm_ct <- ggplot()
pm_ct <- pm_ct + geom_polygon(data = test_map, aes(x=long, y=lat, group=group, fill=black_p/100), color="white", size=.25)
pm_ct <- pm_ct + geom_polygon(data = test_borders, aes(x=long, y=lat, group=group), fill=NA, color = "black", size=0.5)
pm_ct <- pm_ct + coord_map()
pm_ct <- pm_ct + scale_fill_distiller(type="seq", trans="reverse", palette = "Reds", breaks=pretty_breaks(n=9), labels=percent, name="Stops")
pm_ct <- pm_ct + theme_nothing(legend=TRUE)
pm_ct <- pm_ct + labs(x=NULL, y=NULL, title=paste("Where black drivers are pulled over by", town_name, "police"))
#pm_ct <- pm_ct + theme_bw(base_family="Calibri")
#pm_ct <- pm_ct + theme(panel.grid.major=element_blank())
#pm_ct <- pm_ct + theme(panel.grid.minor=element_blank())
#pm_ct <- pm_ct + theme(panel.border=element_blank())
pm_ct <- pm_ct + theme(text = element_text(size=15))
#pm_ct <- pm_ct + theme(axis.ticks=element_blank())
#pm_ct <- pm_ct + theme(axis.text.x=element_blank())
pm_ct <- pm_ct + theme(plot.title=element_text(face="bold", hjust=.4))
pm_ct <- pm_ct + theme(plot.subtitle=element_text(face="italic", size=9, margin=margin(l=20)))
pm_ct <- pm_ct + theme(plot.caption=element_text(size=12, margin=margin(t=12), color="#7a7d7e", hjust=0))
#pm_ct <- pm_ct + scale_fill_gradient(low = "#b2b2b2", high = "tomato", labels = percent)
pm_ct <- pm_ct + annotate("segment", x = -73.1, xend = -73.06, y = 41.64, yend = 41.64, colour = "lightblue", size=.5)
pm_ct <- pm_ct + annotate("point", x = -73.1, y = 41.64, colour = "lightblue", size = 2)
pm_ct <- pm_ct + annotate("text", x = -73.04, y = 41.64, label = "Watertown", size=5, colour="gray30")
pm_ct <- pm_ct + annotate("segment", x = -72.97, xend = -72.93, y = 41.57, yend = 41.57, colour = "lightblue", size=.5)
pm_ct <- pm_ct + annotate("point", x = -72.97, y = 41.57, colour = "lightblue", size = 2)
pm_ct <- pm_ct + annotate("text", x = -72.915, y = 41.57, label = "Wolcott", size=5, colour="gray30")
pm_ct <- pm_ct + annotate("point", x = -72.9, y = 41.57, colour="white", size=.2)
pm_ct <- pm_ct + theme(legend.key.size = unit(1, "cm"))
pm_ct

# labs(title=" (percent by tract)", fill="")
print(pm_ct)

ggsave(pm_ct, file = "img/stops_waterbury_black.png", width = 8, height = 6, type = "cairo-png")
# Minorities
pm_ct <- ggplot()
pm_ct <- pm_ct + geom_polygon(data = test_map, aes(x=long, y=lat, group=group, fill=minority_p/100), color="white", size=.25)
pm_ct <- pm_ct + geom_polygon(data = test_borders, aes(x=long, y=lat, group=group), fill=NA, color = "black", size=0.5)
pm_ct <- pm_ct + coord_map()
pm_ct <- pm_ct + scale_fill_distiller(type="seq", trans="reverse", palette = "Reds", breaks=pretty_breaks(n=9), labels=percent, name="Stops")
pm_ct <- pm_ct + theme_nothing(legend=TRUE)
pm_ct <- pm_ct + labs(x=NULL, y=NULL, title=paste("Where minority drivers are pulled over by", town_name, "police"))
#pm_ct <- pm_ct + theme_bw(base_family="Calibri")
#pm_ct <- pm_ct + theme(panel.grid.major=element_blank())
#pm_ct <- pm_ct + theme(panel.grid.minor=element_blank())
#pm_ct <- pm_ct + theme(panel.border=element_blank())
pm_ct <- pm_ct + theme(text = element_text(size=15))
#pm_ct <- pm_ct + theme(axis.ticks=element_blank())
#pm_ct <- pm_ct + theme(axis.text.x=element_blank())
pm_ct <- pm_ct + theme(plot.title=element_text(face="bold", hjust=.4))
pm_ct <- pm_ct + theme(plot.subtitle=element_text(face="italic", size=9, margin=margin(l=20)))
pm_ct <- pm_ct + theme(plot.caption=element_text(size=12, margin=margin(t=12), color="#7a7d7e", hjust=0))
#pm_ct <- pm_ct + scale_fill_gradient(low = "#b2b2b2", high = "tomato", labels = percent)
pm_ct <- pm_ct + annotate("segment", x = -73.1, xend = -73.06, y = 41.64, yend = 41.64, colour = "lightblue", size=.5)
pm_ct <- pm_ct + annotate("point", x = -73.1, y = 41.64, colour = "lightblue", size = 2)
pm_ct <- pm_ct + annotate("text", x = -73.04, y = 41.64, label = "Watertown", size=5, colour="gray30")
pm_ct <- pm_ct + annotate("segment", x = -72.97, xend = -72.93, y = 41.57, yend = 41.57, colour = "lightblue", size=.5)
pm_ct <- pm_ct + annotate("point", x = -72.97, y = 41.57, colour = "lightblue", size = 2)
pm_ct <- pm_ct + annotate("text", x = -72.915, y = 41.57, label = "Wolcott", size=5, colour="gray30")
pm_ct <- pm_ct + annotate("point", x = -72.9, y = 41.57, colour="white", size=.2)
pm_ct <- pm_ct + theme(legend.key.size = unit(1, "cm"))
pm_ct

# labs(title=" (percent by tract)", fill="")
print(pm_ct)

ggsave(pm_ct, file = "img/stops_waterbury_minorities.png", width = 8, height = 6, type = "cairo-png")
# White
pm_ct <- ggplot()
pm_ct <- pm_ct + geom_polygon(data = test_map, aes(x=long, y=lat, group=group, fill=white_p/100), color="white", size=.25)
pm_ct <- pm_ct + geom_polygon(data = test_borders, aes(x=long, y=lat, group=group), fill=NA, color = "black", size=0.5)
pm_ct <- pm_ct + coord_map()
pm_ct <- pm_ct + scale_fill_distiller(type="seq", trans="reverse", palette = "Reds", breaks=pretty_breaks(n=9), labels=percent, name="Stops")
pm_ct <- pm_ct + theme_nothing(legend=TRUE)
pm_ct <- pm_ct + labs(x=NULL, y=NULL, title=paste("Where white drivers are pulled over by", town_name, "police"))
#pm_ct <- pm_ct + theme_bw(base_family="Calibri")
#pm_ct <- pm_ct + theme(panel.grid.major=element_blank())
#pm_ct <- pm_ct + theme(panel.grid.minor=element_blank())
#pm_ct <- pm_ct + theme(panel.border=element_blank())
pm_ct <- pm_ct + theme(text = element_text(size=15))
#pm_ct <- pm_ct + theme(axis.ticks=element_blank())
#pm_ct <- pm_ct + theme(axis.text.x=element_blank())
pm_ct <- pm_ct + theme(plot.title=element_text(face="bold", hjust=.4))
pm_ct <- pm_ct + theme(plot.subtitle=element_text(face="italic", size=9, margin=margin(l=20)))
pm_ct <- pm_ct + theme(plot.caption=element_text(size=12, margin=margin(t=12), color="#7a7d7e", hjust=0))
#pm_ct <- pm_ct + scale_fill_gradient(low = "#b2b2b2", high = "tomato", labels = percent)
pm_ct <- pm_ct + annotate("segment", x = -73.1, xend = -73.06, y = 41.64, yend = 41.64, colour = "lightblue", size=.5)
pm_ct <- pm_ct + annotate("point", x = -73.1, y = 41.64, colour = "lightblue", size = 2)
pm_ct <- pm_ct + annotate("text", x = -73.04, y = 41.64, label = "Watertown", size=5, colour="gray30")
pm_ct <- pm_ct + annotate("segment", x = -72.97, xend = -72.93, y = 41.57, yend = 41.57, colour = "lightblue", size=.5)
pm_ct <- pm_ct + annotate("point", x = -72.97, y = 41.57, colour = "lightblue", size = 2)
pm_ct <- pm_ct + annotate("text", x = -72.915, y = 41.57, label = "Wolcott", size=5, colour="gray30")
pm_ct <- pm_ct + annotate("point", x = -72.9, y = 41.57, colour="white", size=.2)
pm_ct <- pm_ct + theme(legend.key.size = unit(1, "cm"))
pm_ct

# labs(title=" (percent by tract)", fill="")
print(pm_ct)

ggsave(pm_ct, file = "img/stops_waterbury_white.png", width = 8, height = 6, type = "cairo-png")