R: Automatically Creating Graphs from Dataframes

Is the dataset always going to be ordered correctly, so the plot will go from row 1->2->3 etc in a single line? If so, we can make the node info dataframe by simply subsetting the ID column. If we put the steps in a function, it becomes a simple 1-liner:

plot_nodes <- function(x) {
    id = x$id
    a = id[1:length(id)-1]
    b = id[2:length(id)]
    graph.data.frame(data.frame(a,b), directed=TRUE)
}

graph <- plot_nodes(route_1)
plot(simplify(graph))

enter image description here