gpt4 book ai didi

r - ggplot fortify 忽略空间数据的顺序

转载 作者:行者123 更新时间:2023-12-01 21:49:53 26 4
gpt4 key购买 nike

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

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

Qgis:

qgis image

sp中看起来不错:

sp image

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

ggplot image

<小时/>

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

( 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则不然: sp sample ggplot sample

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

最佳答案

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

关于r - ggplot fortify 忽略空间数据的顺序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34343571/

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