I'd like to make a map in R of the continental U.S. (using the maps package), where one state is filled in in black (CA) and one state (TX) is filled in with cross-hatches or some other pattern. The rest of the states should have black borders with no fill. I'm sure there's a simple solution, but I haven't found it yet.
问问题
3362 次
3 回答
4
我最近遇到了同样的问题,但是有太多的状态无法用多边形手动孵化。似乎只需在特定状态的地图中添加密度 = 10 就会用阴影条填充它。
因此,对于此处的示例,请尝试:
map("state")
map("state", add = TRUE, region = c("texas"), density=10, fill=TRUE)
map("state", add = TRUE, region = c("california"), fill=TRUE)
于 2014-07-29T19:06:19.403 回答
3
我可以通过保存状态数据并重新绘制来使其工作。需要进行一些polygon
调整,以便状态多边形的轮廓以正确的顺序绘制,而不会加倍自身。需要多少摆弄可能取决于您想要的状态多边形。在这种情况下,我只需要颠倒德克萨斯/新墨西哥的边界。
library(maps)
map("state")
tempplot <- map("state", add = TRUE, region = c("texas"),plot=FALSE)
# fix the border with new mexico to draw it in the correct order
tempplot$x[829:861] <- tempplot$x[861:829]
tempplot$y[829:861] <- tempplot$y[861:829]
polygon(
na.omit(tempplot$x),
na.omit(tempplot$y),
border=1,
density=10
)
map("state", add = TRUE, region = c("california"), fill=TRUE, col="black")
于 2013-01-29T00:52:21.477 回答
1
这应该是一个好的开始。
library(maps)
map('state')
map("state", col = "black", fill = TRUE, add = TRUE, region = c('california'))
map("state", col = "red", fill = TRUE, add = TRUE, region = c('texas'))
PS:交叉影线填充图案通常不被认可。所以我在这里用红色填充德克萨斯。
编辑
一种选择是使用lty和lwd来区分状态。它看起来很棘手,但结果很清楚。
map("state", lty = 3)
map("state", col = "black", fill = TRUE, add = TRUE, region = c('california'))
map("state", lty=1,lwd = 3, fill = FALSE, add = TRUE, region = c('texas'))
于 2013-01-29T00:23:25.763 回答