问题
I want to draw a US map with some states have blue color and others have white color
Now, I have the list of names of state:
c=c("ILLINOIS", "KANSAS","LOUISIANA","MAINE","MICHIGAN","MINNESOTA","MISSISSIPPI" )
However, when I use:
map(database = "state",regions = c,col = "blue",fill=T)
It only shows:
This is not I want, I want to see other states with white color, what should I do?
回答1:
@rawr solution in comments worked. to create a full map with fill colors:
map(database = "state")
map(database = "state",regions = c,col = "blue",fill=T,add=TRUE)
回答2:
At the moment you are asking R to only plot those states so you need to drop the region
-argument and figure out a way to match color choices with the names of the states:
require(maps)
namevec <- map(database = "state", col = "blue",fill=T, namesonly=TRUE)
> str(namevec)
chr [1:63] "alabama" "arizona" "arkansas" "california" ...
So try this:
map(database = "state",col = c("white", "blue")[1+(namevec %in% tolower(c) )],fill=T)
来源:https://stackoverflow.com/questions/34301835/how-to-color-states-in-us-map-in-r