首页 文章

geom_line图中的顶点顺序错误

提问于
浏览
3

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 回答

  • 4

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

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

    enter image description here

相关问题