------------------------------
Message: 24
Date: Wed, 15 Dec 2010 15:03:51 -0800
From: "Robert J. Hijmans" <r.hijmans at gmail.com>
To: r-sig-geo at r-project.org
Subject: Re: [R-sig-Geo] Spatial network plots?
Message-ID:
<AANLkTik=SF4GY34Qf=TSmWoYwmxSqzmJvM_in0aVdSys at mail.gmail.com>
Content-Type: text/plain; charset=ISO-8859-1
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')],
npts, breakAtDateLine=TRUE, addStartEnd=TRUE, sp=TRUE)
library(maptools)
data(wrld_simpl)
plot(wrld_simpl)
plot(rts, col='red', add=T)
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)
plot(wrld_simpl, add=T)
lines(rts, col='red')
Robert
On Wed, Dec 15, 2010 at 1:58 PM, Edzer Pebesma
<edzer.pebesma at uni-muenster.de> 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.
Thanks in advance,
Bogdan State
PhD Student
Department of Sociology
Stanford University
bstate at stanford.edu
? ? ? [[alternative HTML version deleted]]