I am intending to plot a county level map with 5 colors depending on a value of an attribute. I did that with no problems. Now, I want to add the state borders and the end result is not good. The border lines are too straight and the limits of the states are not well plotted. They do not follow the actual limits of the states.
Here is the code I am using:
# Pick the colors for the categorical values
colors = c("#CC0000", "#FF9999", "#E0E0E0", "#99FF99", "#00CC00")
#Creates a new variable with the categories.
data$colorBuckets <- as.numeric(cut(data$Slope, c(-0.30, -0.20, -0.10, 0.10,
0.20, 0.30)))
# Put a 3 (equivalent to slope 0) when there is NA's
data$colorBuckets[is.na(data$colorBuckets)] <- 3
# Matches the values of FIPS with the color categories
colorsmatched <- data$colorBuckets
library(mapproj)
# Map colored counties according the categories
map("county", col = colors[colorsmatched], fill = TRUE, resolution = 0,
lty = 0, projection = "polyconic")
# Add border around each county
map("county", col = "gray", fill = FALSE, add = TRUE, lty = 1, lwd = 0.2,
projection = "polyconic")
# Add border to each state (THIS IS THE PROBLEMATIC STEP)
map("state", col = "black", fill = FALSE, add = TRUE, lty = 1, lwd = 0.4,
projection = "polyconic")
Any idea why this may be happening?