Guest User

Untitled

a guest
Jun 20th, 2018
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.32 KB | None | 0 0
  1. # Draw a basic choropleth map, using R.
  2. # This example creates a map of the United States, based on completely
  3. # fictional information. Since we just survived an election, I used red and
  4. # blue as my color choices.
  5.  
  6. library(maps)
  7. library(mapdata)
  8.  
  9.  
  10. # If either library() call fails, try these.
  11. install.packages("maps", dep=TRUE)
  12. install.packages("mapdata", dep=TRUE)
  13.  
  14.  
  15. # Create some fake data
  16. lower.48 <- c('Alabama', 'Alaska', 'Arizona', 'Arkansas', 'California',
  17. 'Colorado', 'Connecticut', 'Delaware', 'Florida', 'Georgia', 'Idaho',
  18. 'Illinois', 'Indiana', 'Iowa', 'Kansas', 'Kentucky', 'Louisiana', 'Maine',
  19. 'Maryland', 'Massachusetts', 'Michigan', 'Minnesota', 'Mississippi',
  20. 'Missouri', 'Montana', 'Nebraska', 'Nevada', 'New Hampshire', 'New Jersey',
  21. 'New Mexico', 'New York', 'North Carolina', 'North Dakota', 'Ohio', 'Oklahoma',
  22. 'Oregon', 'Pennsylvania', 'Rhode Island', 'South Carolina', 'South Dakota',
  23. 'Tennessee', 'Texas', 'Utah', 'Vermont', 'Virginia', 'Washington',
  24. 'West Virginia', 'Wisconsin', 'Wyoming')
  25.  
  26. colors <- c(rep(c('red','blue'),25), 'red')
  27.  
  28.  
  29. # Draw a simple choropleth map.
  30. map('state', region=lower.48, col=colors, fill=TRUE)
  31. map("state",col = "white",fill=FALSE,add=TRUE,lty=1,lwd=1, bg = 'slategray')
  32.  
  33.  
  34. # You only need this if you want to save your image.
  35. #savePlot(filename="Map.png", type="png")
Add Comment
Please, Sign In to add comment