library('devtools')
load_all('~/lehmansociology')
## Loading lehmansociology
library('maps')
library('ggmap')
library(mapproj)
library("RColorBrewer")

In this template we will use the poverty data to make maps.

To see a nicely formatted copy of this click on the Knit HTML button at the top of this window.

This shows the outline maps for the US, states and counties.

# Show one map per image (meaning 1 in each row and column) 
par(mfrow = c(1, 1) )
# Set the margins
par(xpd=TRUE)


# Make some empty maps (just to show how to do it)
map("usa")
map("state")
map("county")
# This loads the fips information from the county map data. Only includes the lower 48 states.
data(county.fips)

Introduction

Write your introduction here.

# Add colors, see color documentation for more information on how to customize. 
colors<-brewer.pal(7,"Greens")

# Divide the poverty rate into levels and create a new variable for the level of each county.
levels <- cut(poverty.counties$PCTPOVALL_2013,c(10, 20, 30, 40, 50, 60))
poverty.counties$colorBuckets <- as.numeric(levels)
                                            
# Match up the poverty data with the county map data using the fips value.
colorsmatched <- poverty.counties$colorBuckets[match(county.fips$fips, poverty.counties$FIPStxt)]

# Create the map, matching the county data with the colors
map("county", col = colors[colorsmatched], fill = TRUE,
    resolution = 0, lty = 0, bty='L', projection = "polyconic", mar=c(0,10,0,0))

# This adds the border around the states.
map("state", col = "black", fill = FALSE, add = TRUE,
    lty = 1, lwd = 0.2, projection = "polyconic", mar=c(0,10,0,0))
                                                                                                                                                                                                                                    
# Add a title and legend. There are many other options for text and customization.
title("Poverty Percent by County, 2013")
par(xpd=TRUE)
leg.txt <- c("<10%", "11-20%", "21-30%", "31-40%", "41-50%", ">50%")
legend("right", leg.txt, horiz = FALSE, fill = colors, inset=c(-.08,0))