2017-08-05 55 views
0

我有這樣的代碼,其產生本地圖:R:在geom_polygon ggmap移除額外線

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") 

enter image description here

正如你可以看到,有在頂部左側有一個額外的三角形。我怎樣才能擺脫它?

+0

使用geom_map而不是geom_polygon –

回答

0

一個非常簡單的方法就是減少y限制的最大值以去除該上限並防止構建三角形。剛剛從43.26184改變scale_y_continuous價值43.25184的伎倆:

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") 

enter image description here

當然,你也可以只篩選出上述iowa_counties一定緯度的點。