Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Draw a basic choropleth map, using R.
- # This example creates a map of the United States, based on completely
- # fictional information. Since we just survived an election, I used red and
- # blue as my color choices.
- library(maps)
- library(mapdata)
- # If either library() call fails, try these.
- install.packages("maps", dep=TRUE)
- install.packages("mapdata", dep=TRUE)
- # Create some fake data
- lower.48 <- c('Alabama', 'Alaska', 'Arizona', 'Arkansas', 'California',
- 'Colorado', 'Connecticut', 'Delaware', 'Florida', 'Georgia', 'Idaho',
- 'Illinois', 'Indiana', 'Iowa', 'Kansas', 'Kentucky', 'Louisiana', 'Maine',
- 'Maryland', 'Massachusetts', 'Michigan', 'Minnesota', 'Mississippi',
- 'Missouri', 'Montana', 'Nebraska', 'Nevada', 'New Hampshire', 'New Jersey',
- 'New Mexico', 'New York', 'North Carolina', 'North Dakota', 'Ohio', 'Oklahoma',
- 'Oregon', 'Pennsylvania', 'Rhode Island', 'South Carolina', 'South Dakota',
- 'Tennessee', 'Texas', 'Utah', 'Vermont', 'Virginia', 'Washington',
- 'West Virginia', 'Wisconsin', 'Wyoming')
- colors <- c(rep(c('red','blue'),25), 'red')
- # Draw a simple choropleth map.
- map('state', region=lower.48, col=colors, fill=TRUE)
- map("state",col = "white",fill=FALSE,add=TRUE,lty=1,lwd=1, bg = 'slategray')
- # You only need this if you want to save your image.
- #savePlot(filename="Map.png", type="png")
Add Comment
Please, Sign In to add comment