几行代码暴露了我的问题。当我处理世界地图并引入投影时,我总是会得到一些看起来很奇怪的水平线。请查看 https://www.rdocumentation.org/packages/ggplot2/versions/1.0.0/topics/coord_map
我以新西兰为例
library(ggplot2)
nz <- map_data("nz")
# Prepare a map of NZ
nzmap <- ggplot(nz, aes(x = long, y = lat, group = group)) +
geom_polygon(fill = "white", colour = "black")
# Plot it in cartesian coordinates
nzmap
# With correct mercator projection
nzmap + coord_map()
Run Code Online (Sandbox Code Playgroud)
效果很好。现在让我们对世界做同样的事情
world <- map_data("world")
# Prepare a map of the world
worldmap <- ggplot(world, aes(x = long, y = lat, group = group)) +
geom_polygon(fill = "white", colour = "black")
# Plot it in cartesian coordinates
worldmap
##but the following is a disaster!
# With correct mercator projection
worldmap + coord_map()
Run Code Online (Sandbox Code Playgroud)
我发现带有投影的水平线问题已经持续了很长一段时间,但我只能找到经验丰富的帖子,并且我认为这个问题很久以前就已经解决了。请在下面找到我的会话信息。有什么办法解决这个问题吗?它仍然是一个未解决的错误吗?
这是 ggplot 中一个非常常见的问题,但幸运的是它很容易修复:
worldmap + coord_map(xlim=c(-180,180))
产生
解决方案来自:为什么 coord_map 会产生奇怪的输出?