我正在努力在地图上添加文本,我使用map.text
函数构建了该文本。
我按照自己的意愿为我的状态着色,但现在,我还想在地图上添加一些数字/数字。
这是我以前用过的代码:
library(“maps”)
win.obama = c( "California", "Colorado", "Connecticut", "District of Columbia",
"Delaware", "Florida", "Hawaii", "Iowa" ,
"Illinois", "Massachusetts", "Maryland", "Maine" ,
"Michigan", "Minnesota", "New Hampshire", "New Jersey",
"New Mexico", "Nevada", "New York", "Ohio",
"Oregon", "Pennsylvania", "Rhode Island", "Virginia",
"Vermont", "Washington", "Wisconsin")
win.romney = c("Alaska", "Alabama", "Arkansas", "Arizona", "Georgia", "Idaho",
"Indiana", "Kansas", "Kentucky", "Louisiana", "Missouri", "Mississippi",
"Montana", "North Carolina", "North Dakota", "Nebraska", "Oklahoma", "South Carolina",
"South Dakota", "Tennessee", "Texas", "Utah", "West Virginia", "Wyoming")
map(database = "state")
map(database = "state", regions = win.obama, col = "blue", fill=T, add=TRUE)
map(database = "state", regions = win.romney, col = "red2", fill=T, add=TRUE)
我该怎么做?
答案 0 :(得分:2)
您可以使用map.text
在不同地区的地图上放置文字:
例如:
map.text(database="state", region="Alabama", labels="Ala", add=TRUE)
有关该功能的详细信息,请参阅?map.text
。
作为旁注,您可以通过以下方式显示地图:
map(database="state", regions=c(win.obama, win.romney), col=rep(c("blue", "red2"), c(length(win.obama), length(win.romney))), fill=TRUE)