# Help! How do you make a choropleth in R!

#### oldwarplanes

##### New Member
So I have a data set with the number of violent crimes known to police in various counties in Ohio since 1990 (the file is attached). Making the dataset (from now on, I'll refer to it as OH) readable in R was enough of a task for me and now figuring out how to make a choropleth is making me crazy!

So first, I know I need to install map packages, which I did with:
Code:
install.packages("maps")
library(maps)
install.packages("mapproj")
library(mapproj)
It gave me an option of a bunch of different maps; obviously, I chose the USA (OH) map. From the tutorial I'm looking at, it says a version of my data should be installed with the maps library and you use the code:
Code:
data(OH)
But I really have no idea what the tutorial is talking about. Can anyone either link me to a better one or explain how I would proceed from this point? Thanks!

#### gianmarco

##### TS Contributor
Hi,
I am having a somewhat similar need, and I am finding useful this document on ggmap.
Let give it a read.

Hope it helps bit,
Gm

#### bugman

##### Super Moderator
I have found this page to be really helpful.

But @ oldwarplanes, what more specially are you having trouble with in th tutorial?

#### oldwarplanes

##### New Member
I was given only the following as an example, so I really have no idea where to go from this:

Code:
install.packages("maps")
library(maps)
install.packages("mapproj")
library(mapproj)

# use the version installed with maps library!
data(unemp)

# set up color scheme and intervals
colors <- c("darkgreen", "seagreen","yellowgreen", "yellow",
"orange","red")
Intervals <- as.numeric(cut(unemp$unemp,c(0,2,4,6,8,10,100))) Legend <- c("<2%", "2-4%", "4-6%", "6-8%", "8-10%", ">10%") # match unemployment data to map regions by fips codes data(county.fips) Matches <- Intervals[match(county.fips$fips, unemp$fips)] # draw map map("county", col = colors[Matches], fill = TRUE, resolution = 0,lty = 0, projection = "polyconic") # draw state boundaries map("state", col = "purple", fill = FALSE, add = TRUE, lty = 1, lwd = 0.3, projection="polyconic") # add title and legend title("Unemployment by county, 2009") legend("topright",Legend, horiz = TRUE, fill = colors) ############################################################## # map Washington State # see http://people.reed.edu/~jones/141/FIPSchar.dat county.fips[county.fips$fips > 53000 & county.fips\$fips < 54000,]
# rows 2892:2933
county.fips[2892:2933,]

map("county",region="washington",
col = colors[Matches[2892:2933]], fill = TRUE,
resolution = 0, lty = 0, projection = "polyconic")
title("Washington State Unemployment, 2009")
legend("topright",Legend, horiz = TRUE, fill = colors)
I've been playing around with that example (with the dataset he gave for the example), and I still don't feel like I have the hang of it at all. I understand that the first bit of code is installing maps. What I really don't get is the data(unemp) bit he put in there. I don't know what that's supposed to do...

#### bugman

##### Super Moderator
data(unemp) is loading your data set.

Did you read the link I posted?

I've been playing around with that example (with the dataset he gave for the example), and I still don't feel like I have the hang of it at all
Please be clear. Playing around with that example - great. But where have you got to?

Last edited:

#### bryangoodrich

##### Probably A Mammal
There's this magical function in R called help. When you see a command you don't understand, like data, just type

Code:
help("data")
For a shorthand, you can just do "?data" instead. Read the documentation. It tells you what the functions do.