ggplot fortify忽略了空间数据的顺序。

3

我需要使用ggplot的fortify功能,但在使用Open Streetmap地图文件时,fortify会丢失一些线条的顺序。文件中的顺序必须是正确的,因为qgis和sp包在绘制图表时没有问题。

这里是一个德国城镇道路的示例:

Qgis:

qgis image

sp 中看起来不错:

sp image

使用Fortify后,ggplot存在一些问题,例如高速公路的进入/退出:

ggplot image


这是一个关于高速公路部分的小例子

(数据在这里)

library(ggplot)
library(sp)

plot(sample_shape)
ggplot(data = fortify(sample_shape), aes(x = long, y = lat, group = group), size = 0.05) + geom_line() + theme_bw()

再次强调,sp 看起来很好,ggplot 不行:

sp示例 ggplot示例

非常感谢任何帮助或提示!

1个回答

3
ggplot()中,应该使用geom_path()而不是geom_point()
library(ggplot2)
library(sp)
load("sample_shape.RData")
ggplot(data = fortify(sample_shape),
       aes(x = long, y = lat, group = group), size = 0.05) +
       geom_path() + theme_bw()

enter image description here


但是道路是线而不是区域(参见qgis / sp图像)。 - ahs85
@ahs85 我刚刚编辑了答案。geom_path() 对于道路来说更好,geom_polygon() 则适用于行政边界。 - maccruiskeen

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接