正如你在下面看到的,在我使用ggplots制作的地图上有一个奇怪的显示问题。任何投影似乎都会出现同样的问题。ggplot2可视化地图/显示错误?
下面是代码: 只有包maps
和ggplot2
需要
mapWorld <- borders("world", colour="gray50", fill="black")
ggplot() + mapWorld +
coord_map("mercator") +
ylim(-90,90)
正如你在下面看到的,在我使用ggplots制作的地图上有一个奇怪的显示问题。任何投影似乎都会出现同样的问题。ggplot2可视化地图/显示错误?
下面是代码: 只有包maps
和ggplot2
需要
mapWorld <- borders("world", colour="gray50", fill="black")
ggplot() + mapWorld +
coord_map("mercator") +
ylim(-90,90)
显然,问题是由穿越0坐标的多边形,在这种世界融合的地方造成的。 R不知道如何关闭这些多边形并将它们投影到世界各地。
此方法重新创建多边形并防止它们穿过0坐标(xlim和ylim)。它适用于任何类型的投影。
require(ggplot2)
require(PBSmapping)
require(data.table)
mapWorld <- map_data("world")
setnames(mapWorld, c("X","Y","PID","POS","region","subregion"))
worldmap = clipPolys(mapWorld, xlim=xlim,ylim=ylim, keepExtra=TRUE)
ggplot() + geom_polygon(data = mapWorld, aes(X,Y,group=PID))
这会引发以下错误:'.clip错误(多边形,xlim,ylim,isPolygons = TRUE,keepExtra): (list)对象不能被强制键入'double'' –
为什么你需要使用?
ggplot() + mapWorld +
coord_map("mercator") +
ylim(-90,90)
如果u只使用
ggplot() + mapWorld
它完美
看起来像数据中的问题。也许在排序中,也许不是。当我运行'summary(mapWorld $ data)'看起来像经度编码从-179到190 ......我期望-180到180 – Gregor
我没有想到这一点。我会尝试与其他数据。谢谢 ! – ePoQ
我可以复制你的问题,但'?border'底部的例子对我来说工作得很好。我99%肯定这是一个数据问题,而不是一个ggplot问题。 – Gregor