# [R-sig-Geo] Spatial network plots?

Robert J. Hijmans r.hijmans at gmail.com
Thu Dec 16 00:03:51 CET 2010

```Bogdan,

The function gcIntermediate  in geosphere can create such lines from
"from - to" sets of coordinates. Code partly inspired by T Hengl's air
routes script:  http://spatial-analyst.net/worldmaps/airroute.htm

library(geosphere)
library(sp)

n  <- 20
from <- data.frame(lon=runif(n)*-175, lat=runif(n)*80)
to <- data.frame(lon=runif(n)*175, lat=runif(n)*-80)

d <- distHaversine(from[,c('lon', 'lat')], to[,c('lon', 'lat')]) / 1000
npts <- pmax(1, round(sqrt(d)/sqrt(2), 0))  # based on T. Hengl's air
routes example
rts <- gcIntermediate(from[,c('lon', 'lat')], to[,c('lon', 'lat')],

library(maptools)
data(wrld_simpl)
plot(wrld_simpl)
points(from, col='blue')
points(to, col='green')

# A next step could be to use the rasterize function in raster to
create a line-density raster.
# this takes a long time

library(raster)
r <- raster()
res(r) <- 5
r <- rasterize(rts, r, fun='count')

plot(r)
lines(rts, col='red')

Robert

On Wed, Dec 15, 2010 at 1:58 PM, Edzer Pebesma
<edzer.pebesma at uni-muenster.de> wrote:
> Bogdan, you may also like this:
>
>
> Earlier this evening I tried to leave a note there to ask the author for
> the script, but failed, it seems.
>
> On 12/15/2010 10:43 PM, Bogdan State wrote:
>> Hi everyone,
>>
>> I hope I am posting on the right list. I have recently started analyzing
>> some data that involves connections between people in various cities. I
>> would be extremely grateful if someone could point me towards a solution for
>> drawing "geographical networks" similar to the flight maps at the back of
>> airline magazines (i.e. New York connects to L.A. etc.). I have looked at
>> all the usual suspects so far: sp/maptools for GIS (mostly by using spplot)
>> and igraph/statnet for social network analysis. None of the packages seems
>> to do exactly what I need, but I hope I am wrong.
>>
>> Bogdan State
>> PhD Student
>> Department of Sociology
>> Stanford University
>>
>> bstate at stanford.edu
>>
>>       [[alternative HTML version deleted]]
>>
>> _______________________________________________
>> R-sig-Geo mailing list
>> R-sig-Geo at r-project.org
>> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>
> --
> Edzer Pebesma
> Institute for Geoinformatics (ifgi), University of Münster
> Weseler Straße 253, 48151 Münster, Germany. Phone: +49 251
> 8333081, Fax: +49 251 8339763  http://ifgi.uni-muenster.de
> http://www.52north.org/geostatistics      e.pebesma at wwu.de
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>

```