(This article was first published on

**is.R()**, and kindly contributed to R-bloggers)Today’s short post will show how to make a simple map using map_data().

Let’s assume you have data in a CSV file that may look like this:

Notice the lower case state names; they will make merging the data much easier. The variable of interest we’re going to plot is the relative incarceration rates by race (whites and blacks) across each of the fifty states (we’ll remove DC once we load the data). Using the map_data(“state”) command, we can load a data.frame called “all_states”, shown below:

Merging that data with the data frame we have as a CSV produces:

We can then plot each state and shade it by our variable of interest:

Full code is below:

To

**leave a comment**for the author, please follow the link and comment on his blog:**is.R()**.R-bloggers.com offers

**daily e-mail updates**about R news and tutorials on topics such as: visualization (ggplot2, Boxplots, maps, animation), programming (RStudio, Sweave, LaTeX, SQL, Eclipse, git, hadoop, Web Scraping) statistics (regression, PCA, time series, trading) and more...