R:删除geom_polygon ggmap中的多余行

时间:2017-08-05 18:42:16

标签: r

我有这个代码生成这张地图:

library(ggmap)
library(mapdata)

counties <- map_data("county")
iowa_counties <- subset(counties, region=="iowa")
sq_map2 <- get_map(location = c(-92.55191,42.89219),  maptype = "satellite", source = "google", zoom = 9)
ggmap(sq_map2) + 
scale_y_continuous(limits=c(42.51118, 43.26184), expand=c(0,0)) + 
scale_x_continuous(limits=c(-93.0735, -92.03318), expand=c(0,0)) +
geom_polygon(data = iowa_counties, aes(x=long, y=lat, group=group), fill = NA, color = "white")

the Toxiclibs API

如您所见,左上角有一个额外的三角形。我怎么能摆脱它?

1 个答案:

答案 0 :(得分:0)

一种非常简单的方法是减少y极限的最大值以去除该上部点并防止构造三角形。只需将617中的值从scale_y_continuous更改为43.26184即可:

43.25184

enter image description here

当然,您也可以在library(ggmap) library(mapdata) counties <- map_data("county") iowa_counties <- subset(counties, region=="iowa") sq_map2 <- get_map(location = c(-92.55191,42.89219), maptype = "satellite", source = "google", zoom = 9) ggmap(sq_map2) + scale_y_continuous(limits=c(42.51118, 43.26184), expand=c(0,0)) + scale_x_continuous(limits=c(-93.0735, -92.03318), expand=c(0,0)) + geom_polygon(data = iowa_counties, aes(x=long, y=lat, group=group), fill = NA, color = "white") 中过滤掉某个纬度以上的点。