小编hie*_*erb的帖子

geom_point并不总是显示在地图上

我尝试将具有自定义坐标的点添加到地图中。一般来说,这似乎适用于 sf 包提供的 NC 地图。但是,它在我从https://gdz.bkg.bund.de/index.php/default/open-data/verwaltungsgebiete-1-2-500-000-stand-31-12-下载的 shapefile 中不起作用vg2500-12-31.html - 只要我只绘制这张新地图。如果我同时绘制两个形状文件,第二个形状文件上的点会突然出现。如何将自定义点仅添加到德国地图?

library("ggplot")    
library("sf")

nc <- st_read(system.file("shape/nc.shp", package="sf"))
ger_shape <- st_read("data/shapefiles/VG2500_LAN.shp")
ger_shape <- ger_shape[which(ger_shape$GF == 4),]

city <- data.frame(name = "1", lat = 35.7721, lng = -78.63861)
city2 <- data.frame(name = c("2","3"), lat = c(53,50), lng = c(10.2,10.2))

ggplot() +
  geom_sf(data = nc) + 
  coord_sf(lims_method = "geometry_bbox") +
  geom_point(data = city, aes(x = lng, y = lat), color = 'red') 
Run Code Online (Sandbox Code Playgroud)

带有红点的 NC 地图

ggplot() +
  geom_sf(data = ger_shape) + 
  coord_sf(lims_method = "geometry_bbox") + …
Run Code Online (Sandbox Code Playgroud)

r ggplot2 r-sf

2
推荐指数
1
解决办法
387
查看次数

标签 统计

ggplot2 ×1

r ×1

r-sf ×1