It sounded like a loud bang but it’s months away from Independence Day… and I am on the more questionable side of the “Delmar Divide”….

So it’s got me curious:

  • How much crime are there in St Louis?
  • Where do the crimes take place?

To help answer this question, I downloaded a data set of all the crimes in St Louis region (don’t remember where I got the data, will add a link if I find it again) and graphed it using R to visualize the crime types and location.

There’s a lot of data cleaning and extraction:


#load librarys
library(ggmap)
library(maps)

# read int eh data set
d <- read.csv("Stl_Crime_Data.csv", stringsAsFactors = F)

# clean up the data and pull out just the relavent parts (i.e. location and type of crime)
names(d) <- tolower(names(d))
d <- data.frame(crime = d$ucrcrime, location = d$location, stringsAsFactors = F)

# split up longitude and latitude
location <- d$location
location <- strsplit(location, "\n")

# clean up data some more
gc <- lapply(location, function(x) {x[2]})
gc <- lapply(gc, function(y) {gsub("\\(", "", y)})
gc <- lapply(gc, function(y) {gsub("\\)", "", y)})
gc <- sapply(gc, function(x) {strsplit(x, split = ",")})

# extract longitude and lattitude
lat <- sapply(gc, function(x) {x[1]})
lon <- sapply(gc, function(x) {x[2]})

# convert to number
d$lon <- as.numeric(lon)
d$lat <- as.numeric(lat)

# remove useless location labels
d <- d[, -2]
d$crime <- factor(d$crime)

While any crime is undesirable, here’s my attempt to break it down into serious, moderate and property crimes:


serious <- subset(d, d$crime == "Aggravated Assault" |
 d$crime == "Criminal Homicide" |
 d$crime == "Forcible Rape" |
 d$crime == "Robbery")

moderate <- subset(d, d$crime == "Disorderly Conduct" |
 d$crime == "Other assaults" |
 d$crime == "Sex Offenses" |
 d$crime == "Prostitution and Commercialized Vice")

property <- subset(d, d$crime == "Burglary" |
 d$crime == "Stolen Property" |
 d$crime == "Vandalism" |
 d$crime == "Arson")

For serious crimes:

serious_crime.png

For moderate crimes:

moderate_crime.png

For property crimes:

property_crime.png

Needless to say – I think it’s time to move.

Advertisements