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:

```
library(ggmap)
library(maps)

# read int eh data set
d &lt;- 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) &lt;- tolower(names(d))
d &lt;- data.frame(crime = d\$ucrcrime, location = d\$location, stringsAsFactors = F)

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

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

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

# convert to number
d\$lon &lt;- as.numeric(lon)
d\$lat &lt;- as.numeric(lat)

# remove useless location labels
d &lt;- d[, -2]
d\$crime &lt;- factor(d\$crime)

```

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

```
serious &lt;- subset(d, d\$crime == "Aggravated Assault" |
d\$crime == "Criminal Homicide" |
d\$crime == "Forcible Rape" |
d\$crime == "Robbery")

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

property &lt;- subset(d, d\$crime == "Burglary" |
d\$crime == "Stolen Property" |
d\$crime == "Vandalism" |
d\$crime == "Arson")
```

For serious crimes:

For moderate crimes:

For property crimes:

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