我有以下数据要绘制在美国各州地图上:
x = data.frame(state.x77[,"Income"])
如何将这些绘制为地图上各州的颜色填充?
我可以绘制地图:
map("state", boundary=TRUE, col=colorRampPalette(c("blue","green","yellow","red"))(50), fill=T)
我可以匹配状态:
match(map("state",plot=F)$names, tolower(rownames(x)))
我尝试修改 ?map_data 中的示例:
if (require("maps")) {
states <- map_data("state")
arrests <- USArrests
names(arrests) <- tolower(names(arrests))
arrests$region <- tolower(rownames(USArrests))
choro <- merge(states, arrests, sort = FALSE, by = "region")
choro <- choro[order(choro$order), ]
qplot(long, lat, data = choro, group = group, fill = assault,
geom = "polygon")
qplot(long, lat, data = choro, group = group, fill = assault / murder,
geom = "polygon")
}
但我无法调整它。感谢您的帮助。