如何在 ggplot2 上编辑地图

How can I edit a map on ggplot2

我在厄瓜多尔使用此代码

library(rnaturalearth)
install.packages("rnaturalearthhires", repos = "http://packages.ropensci.org", type = "source")
library(rnaturalearthhires)

ecuador<-ne_states(country = "ecuador", returnclass = "sf")

ggplot(data = ecuador)+geom_sf()

我得到这张图:

我真的不需要经度和纬度,但我想离加拉帕戈斯群岛更近一些。

到目前为止,我尝试将经度从几乎 -90 更改为 -82,但这不起作用。

我能做什么?

提前致谢。

编辑: 我从这里得到代码并根据我的需要对其进行调整:

您可以尝试使用 tmap

library(rnaturalearth)
library(rnaturalearthhires)
library(tmap)
library(sf)

厄瓜多尔的简单特征数据

ecuador <- ne_states(country = "ecuador", returnclass = "sf")

设置厄瓜多尔和加拉帕戈斯群岛的边界框坐标

bbox_ec <- st_bbox(c(xmin = -85, xmax = -75, ymax = 2, ymin = -5.5), crs = st_crs(4326))
bbox_gi <- st_bbox(c(xmin = -92, xmax = -89, ymax = 2, ymin = -2), crs = st_crs(4326))

创建地图对象

map_gi <- 
  tm_shape(ecuador, bbox = bbox_gi)+
  tm_polygons()+
  tm_layout(frame = "white")+
  tm_scale_bar()

map_ec <-
  tm_shape(ecuador, bbox = bbox_ec)+
  tm_polygons()+
  tm_scale_bar()

合并地图并打印

map_ec
print(map_gi, vp = grid::viewport(0.2, 0.65, width = 0.5, height = 0.5))

一些问题:

设置加拉帕戈斯群岛插图的边界框和位置是通过目视和反复试验;所以这很可能会得到改善。

地块的比例一定会有所不同。可能有一种方法可以使比例相等,我通过为每个图包含 tmap 比例来采取简单的方法。

reprex package (v1.0.0)

于 2021-04-08 创建