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

时间:2022-02-14 14:58:43

I am having some trouble with ggplot's fortify. When using Open Streetmap shapefile, fortify is loosing the order of some lines. The order must be correct in the file as qgis and the sp package have no problem with the plots.

我对ggplot的fortify有些不满。使用Open Streetmap shapefile时,fortify是放松了一些线条的顺序。订单必须在文件中正确,因为qgis和sp包对图没有问题。

Here is an example with some roads of a German town.

Qgis:

Qgis:

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

Looks good in sp:

在sp:看起来不错

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

But after using fortify, there are some problems in ggplot like the enter/exit of the highway:

但在使用了加固技术后,在ggplot中出现了一些问题,如高速公路的出入口:

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


Here is a little example of that highway-part

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

Again, sp looks nice, ggplot does not: ggplot fortify忽略了空间数据的顺序 ggplot fortify忽略了空间数据的顺序

sp看起来不错,ggplot没有:

Any help or hints is/are highly appreciated!

非常感谢您的帮助和提示!

1 个解决方案

#1


3  

In ggplot() you should use geom_path() instead of geom_point()

在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忽略了空间数据的顺序

#1


3  

In ggplot() you should use geom_path() instead of geom_point()

在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忽略了空间数据的顺序