我正在生成一些地图,我想在地图上显示县的边界ggmap
路线图。这是使用德克萨斯州部分地区的示例。
library(ggmap)
map = get_map(location = c(-95.31619, 28.42460),
zoom = 6, source = "google", maptype="roadmap")
map.plot = ggmap(map)
# get texas counties
counties <- map_data("county")
tx_county <- subset(counties, region == 'texas')
map.plot +
theme_nothing() +
geom_polygon(data = tx_county, aes(x=long, y=lat), fill = NA, color = "red")
然而,生成的数字包含跨越县的线,而不仅仅是边界。
对我做错了什么有什么想法吗?我见过另一个例子here仅使用时它的工作原理ggplot2
但我想使用“路线图”ggmap
.
您需要设置多边形的分组:
map.plot +
geom_polygon(data = tx_county, aes(x=long, y=lat, group = group), fill = NA, color = "red")
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)