如何移动地图并在R中删除其边框
我已经使用此代码创建了一个世界地图
graph_world <-
rnaturalearth::ne_countries(
type = "countries",
scale = "large",
returnclass = "sf") %>%
filter(admin != "Antarctica") %>%
ggplot() +
ggplot2::geom_sf(
fill = "#264653", # Country colour
size = 0 # Line size
) +
ggplot2::coord_sf(
expand = TRUE,
default_crs = sf::st_crs(4326),
xlim = c(-180, 180),
ylim = c(-90, 90))
graph_world
!
我想:
- 卸下左侧和右侧的白色垂直边界。我希望他们要透明。
- 水平移动地图,以使左手边框穿过白令海峡,而不是将Chukotka从俄罗斯其他地区割下。
请注意,删除边界的一种方法是设置coord_sf(展开= f),但这也将删除我要保留的图的任何一侧的空白。
I've created a world map with this code
graph_world <-
rnaturalearth::ne_countries(
type = "countries",
scale = "large",
returnclass = "sf") %>%
filter(admin != "Antarctica") %>%
ggplot() +
ggplot2::geom_sf(
fill = "#264653", # Country colour
size = 0 # Line size
) +
ggplot2::coord_sf(
expand = TRUE,
default_crs = sf::st_crs(4326),
xlim = c(-180, 180),
ylim = c(-90, 90))
graph_world
!
I would like to:
- Remove the white vertical borders on the left and the right. I'd like them to be transparent.
- Shift the map horizontally so that the left hand border goes through the Bering Strait rather than cutting Chukotka off from the rest of Russia.
Note that one way of removing the borders is to set coord_sf(expand = F) but this would also remove the empty space either side of the graph which I want to keep.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
旋转的解决方案是使用ST_CRS()移动投影。我们可以将Prime子午线设置为格林威治以东10度的主要子午线,“+pm = 10”将旋转地图。
但是,如果我们绘制此图,它将在整个地图上创建“条纹”,该地图现在在地图边缘上破坏了以前的连续国家。
我们只需要根据与新地图边缘对齐的微小多边形切片解决方案在这里
然后我们在上面运行上面的代码为了旋转地球而没有污迹。
The solution to the rotation is to shift the the projection using st_crs(). We can set the Prime Meridian as 10 degrees east of Greenwich with "+pm=10 " which rotates the map.
However, if we graph this it will create 'streaks' across the map where countries that were previously contiguous are now broken across the map edge.
We just need to slice our map along a tiny polygon aligned with our new map edge, based on the solution here
Then we run the code above to get a rotated earth without smudges.