Guest User

Untitled

a guest
Oct 21st, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.30 KB | None | 0 0
  1. library(OIdata)
  2. library(RColorBrewer)
  3. library(classInt)
  4.  
  5. # load state data from OIdata package:
  6. data(state)
  7.  
  8. # set constants:
  9. nclr <- 8 # number of bins
  10. min <- 0 # theoretical minimum
  11. max <- 100 # theoretical maximum
  12. breaks <- (max - min) / nclr
  13.  
  14. # set up colors:
  15. plotclr <- brewer.pal(nclr, "Oranges")
  16. plotvar <- state$coal
  17. class <- classIntervals(plotvar,
  18. nclr,
  19. style = "fixed",
  20. fixedBreaks = seq(min, max, breaks))
  21. colcode <- findColours(class,
  22. plotclr)
  23. NAColor <- "gray80"
  24. plotclr <- c(plotclr, NAColor)
  25.  
  26. # map data:
  27. map("state", # base
  28. col = NAColor,
  29. fill = TRUE,
  30. lty = 0)
  31. map("state", # data
  32. col = colcode,
  33. fill = TRUE,
  34. lty = 0,
  35. add = TRUE)
  36. map("state", # border
  37. col = "gray",
  38. lwd = 1.4,
  39. lty = 1,
  40. add = TRUE)
  41.  
  42. # set legend text:
  43. legendText <- c()
  44. for(i in seq(min, max - (max - min) / nclr, (max - min) / nclr)) {
  45. if (i == max(seq(min, max - (max - min) / nclr, (max - min) / nclr))) {
  46. legendText <- c(legendText, paste(round(i,3), "\u2264 n \u2264", round(i + (max - min) / nclr,3)))
  47. if (!is.na(NAColor)) legendText <- c(legendText, "NA")
  48. } else
  49. legendText <- c(legendText, paste(round(i,3), "\u2264 n <", round(i + (max - min) / nclr,3)))
  50. }
  51.  
  52. legend("bottomleft", # position
  53. legend = legendText,
  54. title = "Percent",
  55. fill = plotclr,
  56. cex = 0.56,
  57. bty = "n") # border
Add Comment
Please, Sign In to add comment