Version 0.1.1 of the package stplanr has been released on CRAN. This is a major update with many new functions and a new class definition, SpatialLinesNetwork
, for route planning and network analysis using igraph.
This short post, by myself and package co-author Richard Ellison, describes how stplanr can be used for transport research with a few simple examples from the package documentation. We hope that stplanr is of use to transport researchers and practitioners worldwide and encourage contributions to the development version hosted on GitHub.
Working with origin-destination data
Origin-destination (OD) data is one of the basic data sources for understanding travel behaviour. Usually OD data in R is represented by a table containing at least the following columns:
- Origin ID: a text string identifying the zone in which journeys originate
- Destination ID: a test string identifying the destination zone
- Number of trips: the rate of travel between the unique OD pair
Additional columns can provide a break-down by trip type such as by mode of travel (e.g. car) and time of day. A sample of this data (also referred to as ‘Flow data’ by some statistical organsiations) is provided in the example dataset flows
, as illustrated in the Table below.
library(stplanr)
## Loading required package: sp
library(tmap)
data("flow")
knitr::kable(flow[1:3,c(1, 2, 3, 13)])
920573 | E02002361 | E02002361 | 109 | 59 |
920575 | E02002361 | E02002363 | 38 | 4 |
920578 | E02002361 | E02002367 | 10 | 1 |
To link this data to geographical space we use a dataset stored as a SpatialPointsDataFrame
from the sp package in cents
:
data(cents)
plot(cents)
To link the flow data we can use the command od2line()
to create SpatialLinesDataFrame
:
odlines
Note that the function also accepts a SpatialPolygonsDataFrame
as an input by setting the line start and end point to the zone’s geographic centroid:
odlines
To gain a basic understanding of the rate of travel in this simple travel system, we can plot the odlines
with …read more
Source:: r-bloggers.com