I have made a US state map with the following code, but my data doesn't include all the state, yet the map is coloring in everything anyways. This is strange because I have a variable that clearly assigns one color to each of the regions in the data. When I use the option (exact=TRUE), it doesn't return any map and there's an error. Why isn't it leaving the missing data blank in the map? And does this mean the colors are random?
Here's a link to the data I used in excel format : https://docs.google.com/spreadsheets/d/19VHQdl5-i3r9OzJmJsB9FsrQU5Qk_lnkWmspq0ilAN0/edit?usp=sharing
If you load this excel file into R and save the db as Trump, then all of the following code should work to make this map image
library(maps)
# I created a set of colors I want to use, then a variable that numbers the levels
# The variable has an integer that will tell the map which color in the list to color the region
colors = c("#F1EEF6", "#D4B9DA", "#DF65B0", "#DD1C77", "#980043")
Trump$fraction_votes2 <- as.character(Trump$fraction_votes)
Trump$fraction_votes2 <- as.numeric(Trump$fraction_votes2)
Trump$colorBuckets <- as.numeric(cut(Trump$fraction_votes2, c(0, 0.3, 0.4, 0.5, 0.6, 1.0)))
lnames = c("0-30%", "31-40%", "41-50%", "51-60%", "61-100%")
par(mar=c(1,1,1,1)) # This solves the "plot region too large problem)
map("county", fill=TRUE, exact=TRUE, col = colors[Trump$colorBuckets] , lwd = 0.1)
title(main="Trump: Percentage of Votes Won by County", font.main=2,cex.main=1.2, col.main="maroon4", family="Gill Sans Light")
legend("bottomleft",lnames, col = colors, lwd=3,bty="n"
, cex=0.3, text.font=8, y.intersp=2, title="Voter Percentages\n Key")