gpt4 book ai didi

change centre of map in ggplot2 maps (R)(在ggplot2地图中更改地图中心(R))

转载 作者:bug小助手 更新时间:2023-10-26 20:04:06 30 4
gpt4 key购买 nike



I want to draw a map that is centered on a specific longitude. This is what I've tried:

我想画一张以特定经度为中心的地图。这就是我尝试过的:



require(maps)
require(ggplot2)
require(mapproj)

t <- map_data("world2")

ggplot() +
geom_polygon(data = t, aes(x=long, y = lat, group = group),fill ='gray',color=NA) +
xlab("Longitude") + ylab("Latitude")


Gives map centred at 200 longitude. I want to change it to 180, so that West Africa won't appear on the other opposite of the map. Adding xlim does not seem to work:

给出了以200经度为中心的地图。我想把它改为180,这样西非就不会出现在地图的另一边。添加xlim似乎不起作用:



ggplot() + 
geom_polygon(data = t, aes(x=long, y = lat, group = group),fill ='gray',color=NA) +
xlab("Longitude") + ylab("Latitude") +
coord_cartesian(xlim=c(-20,200))

更多回答
优秀答案推荐

I found a way to do this:

我找到了一种方法:



t <- map_data("world2",wrap=c(-25,335), ylim=c(-35,65))

更多回答

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com