R365: Day 8 – Maps in R

R365: Day 8 –Maps in R

I screwed up and did not get around to writing up yesterday’s post, so I will get two done today. It took me a long time to pick a topic for today; I had originally thought of picking another random package, and while I learned stuff from the other random packages I explored, I felt that I was just scratching the surface of each one. While I have no intention of beating  dead horse and chasing after the same package for 365 days, I want to look more deeply at packages that I find interesting. While looking through {ggplot2}, a package that I will look at some day, I found a reference to a package called {maps}. Having just gone through the databases package, I am very interested in exploring what kind of data resources R has built-in. Sometimes the best way to explore your data is to try out different analyses on a smaller set of data.

The {maps} package has lots of different data sets to choose from. One that I have been particularly intrigued by is the county dataset that contains spatial data of the US counties. I often see people working with ARCGIS and they have nice figures, and I always wished that I had put more effort into learning about spatial mapping data. With a quick modification of the example, you can look at all of the counties in California in a pretty map!


map(‘county’, ‘california’, fill = FALSE, col = palette())

That is pretty nifty, but what I would like to do is look at only a subset of counties, or only states that have names that begin with ‘A’. The basic map() function is very adaptable, and seems to be able to handle these issues.

One of the cool features of the example listed in the vignette was mapping out US unemployment rates from a dataset and coloring in the map. This sort of project would be standard in ARCGIS, but its pretty cool that R can handle it just as easily, and for free.



Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s