Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- library(OIdata)
- library(RColorBrewer)
- library(classInt)
- # load state data from OIdata package:
- data(state)
- # set constants:
- nclr <- 8 # number of bins
- min <- 0 # theoretical minimum
- max <- 100 # theoretical maximum
- breaks <- (max - min) / nclr
- # set up colors:
- plotclr <- brewer.pal(nclr, "Oranges")
- plotvar <- state$coal
- class <- classIntervals(plotvar,
- nclr,
- style = "fixed",
- fixedBreaks = seq(min, max, breaks))
- colcode <- findColours(class,
- plotclr)
- NAColor <- "gray80"
- plotclr <- c(plotclr, NAColor)
- # map data:
- map("state", # base
- col = NAColor,
- fill = TRUE,
- lty = 0)
- map("state", # data
- col = colcode,
- fill = TRUE,
- lty = 0,
- add = TRUE)
- map("state", # border
- col = "gray",
- lwd = 1.4,
- lty = 1,
- add = TRUE)
- # set legend text:
- legendText <- c()
- for(i in seq(min, max - (max - min) / nclr, (max - min) / nclr)) {
- if (i == max(seq(min, max - (max - min) / nclr, (max - min) / nclr))) {
- legendText <- c(legendText, paste(round(i,3), "\u2264 n \u2264", round(i + (max - min) / nclr,3)))
- if (!is.na(NAColor)) legendText <- c(legendText, "NA")
- } else
- legendText <- c(legendText, paste(round(i,3), "\u2264 n <", round(i + (max - min) / nclr,3)))
- }
- legend("bottomleft", # position
- legend = legendText,
- title = "Percent",
- fill = plotclr,
- cex = 0.56,
- bty = "n") # border
Add Comment
Please, Sign In to add comment