library(tidyr)

#### neighborhood map of baltimore
# Neighborhods scraped from Crime and Safety (2010-2013) KML file (original file: 
# https://data.baltimorecity.gov/Neighborhoods/Crime-Safety-2010-2013-Shape/y3aa-iwrk).
# Square region without data is designated as "Unassigned -- Jail" in KML file.

bmore_map <- read.table("Bmore_neighborhoods_from_Crime_and_Safety_kml.txt", 
                        header=FALSE, 
                        sep=" ", 
                        quote="\"", 
                        fill=TRUE, 
                        row.names=1) %>% 
                t() %>% 
                data.frame(check.names=FALSE) %>% 
                gather(key=Neighborhood, value=coords)

# remove empty coords generated by fill argument
bmore_map <- bmore_map[bmore_map$coords != "", ]

# separate coords into latitute and longitude and convert to numeric
bmore_map %<>% separate(col=coords, into=c("longitude", "latitude"), sep=",")
bmore_map[[2]] %<>% as.numeric()
bmore_map[[3]] %<>% as.numeric()

basemap <- geom_polygon(data = bmore_map,
                        mapping = aes(x = longitude,
                                      y = latitude,
                                      group = Neighborhood),
                        color = "grey40",
                        alpha = 0.0)