Visualize violent crime rates in US with choroplethr package

April 11, 2014

(This article was first published on My Life as a Mock Quant in English, and kindly contributed to R-bloggers)

Visualize violent crime rates in different US States with choroplethr package

Visualize violent crime rates in different US States with choroplethr package

I knew choroplethr package by the blog post Animated Choropleths in R a few days ago. As a another visualization tool in R language, I wana try this one.

To install the latest stable release(CRAN) type the following from an R console:


To install the development version using the devtools package from github:

install_github("choroplethr", "trulia")

It's not interesting for me to run just example codes written in choroplethr package, I used other data from rMaps package as a quick data source and visualize it!

install_github("ramnathv/[email protected]")

Now we can use violent crime rates data in US included in rMaps package.

We can create animated choropleths as the following page:

In my case, we just process the data and visualize it as the follwing simple code:

# load packages
# initialization list and get years from violent_crime data
choropleths = list()
# Get years for loop
years <- sort(unique(violent_crime$Year))
# convert to level data
violent_crime$Crime <- cut(violent_crime$Crime, 9)
# Create choropleth component.
for (i in 1:length(years)) {
df <- subset(violent_crime, Year == years[i])
# We need to change the column names for choroplethr function
colnames(df) <- c("Year", "region", "value")
# Cut decimal off df$value <- round(df$value)
title <- paste0("Violent crime rates: ", years[i])
choropleths[[i]] = choroplethr(df, "state", title = title)
# Vizualize it!

The result is published via Dropbox as the following (image)link.


To leave a comment for the author, please follow the link and comment on their blog: My Life as a Mock Quant in English. offers daily e-mail updates about R news and tutorials on topics such as: Data science, Big Data, R jobs, visualization (ggplot2, Boxplots, maps, animation), programming (RStudio, Sweave, LaTeX, SQL, Eclipse, git, hadoop, Web Scraping) statistics (regression, PCA, time series, trading) and more...

If you got this far, why not subscribe for updates from the site? Choose your flavor: e-mail, twitter, RSS, or facebook...

Comments are closed.

Search R-bloggers


Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)