geom_line图中的顶点顺序错误

时间:2016-10-01 21:32:07

标签: r ggplot2

geom_line图中获得奇怪的顶点排序。左手图是基础R;右边是ggplot。

enter image description here

这是我正在使用的shapefile。这将重现情节:

require(ggplot2); require(maptools)
rail = readShapeLines('railnetworkLine.shp')
rail_dat = fortify(rail[1,])
ggplot(rail_dat) + geom_line(aes(long, lat, group=group)) + coord_equal()

知道造成这种情况的原因是什么?强化的数据顺序似乎是正确的,因为单独绘制lines()确认。

1 个答案:

答案 0 :(得分:5)

使用geom_path代替geom_linegeom_line在绘图之前将数据从最低x值(在这种情况下为long)排序,但geom_path以数据帧行的当前顺序绘制数据。

ggplot(rail_dat) + 
  geom_path(aes(long, lat)) + coord_equal()

enter image description here

相关问题