【问题标题】:ggplot fortify ignores order of spatial dataggplot fortify 忽略空间数据的顺序
【发布时间】:2015-12-17 20:21:39
【问题描述】:

我在使用 ggplot 的设防时遇到了一些问题。使用 Open Streetmap shapefile 时,fortify 会丢失某些行的顺序。文件中的顺序必须正确,因为 qgis 和 sp 包对绘图没有问题。

这是一个德国小镇的一些道路示例。

Qgis:

sp 中看起来不错:

但是使用fortify后,ggplot出现了一些问题,比如高速公路的进/出:


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

(data is here)

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 不:

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

【问题讨论】:

    标签: r ggplot2 sp


    【解决方案1】:

    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()
    

    【讨论】:

    • 但是道路是线而不是区域(参见 qgis/sp 图像)。
    • @ahs85 我刚刚编辑了答案。 geom_path() 适用于道路,geom_polygon() 适用于行政边界。
    猜你喜欢
    • 2016-03-30
    • 1970-01-01
    • 2012-10-19
    • 2015-11-24
    • 2020-02-18
    • 2021-02-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多