ggplot fortify 忽略空间数据的顺序
ggplot fortify ignores order of spatial data
我在使用 ggplot 的 fortify 时遇到了一些问题。使用 Open Streetmap shapefile 时,fortify 会丢失某些线条的顺序。文件中的顺序必须正确,因为 qgis 和 sp 包没有问题。
这里是一个德国小镇的一些道路的例子。
Qgis:
在 sp 中看起来不错:
但是使用fortify后,ggplot出现了一些问题,比如highway的enter/exit:
这是高速公路部分的一个小例子
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 不:
任何帮助或提示is/are非常感谢!
在 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()
我在使用 ggplot 的 fortify 时遇到了一些问题。使用 Open Streetmap shapefile 时,fortify 会丢失某些线条的顺序。文件中的顺序必须正确,因为 qgis 和 sp 包没有问题。
这里是一个德国小镇的一些道路的例子。
Qgis:
在 sp 中看起来不错:
但是使用fortify后,ggplot出现了一些问题,比如highway的enter/exit:
这是高速公路部分的一个小例子
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 不:
任何帮助或提示is/are非常感谢!
在 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()