Getting a strange ordering of vertices in a geom_line
plot. Left hand plot is base R; right is ggplot.
Here's the shapefile I'm working with. This will reproduce the plot:
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()
Any idea what is causing this? The data order of fortify seems correct, as plotting separately lines()
confirms.
Use geom_path
instead of geom_line
. geom_line
orders the data from lowest to highest x-value (long
in this case) before plotting, but geom_path
plots the data in the current order of the data frame rows.
ggplot(rail_dat) +
geom_path(aes(long, lat)) + coord_equal()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With