[R-sig-Geo] plot nearest neighbor links
juantomas.sayago at gmail.com
juantomas.sayago at gmail.com
Wed Jun 20 18:55:01 CEST 2012
If I understand your question right you want to create a map of the knn links so you can see them and who is neighbor of who. Right?
The way I would do it is.
I would create the knn nb and then plot it that way.
If you need the codes for that, I can send them in a couple of hours.
Juan.
Sent on the Sprint® Now Network from my BlackBerry®
-----Original Message-----
From: Juliane Struve <juliane_struve at yahoo.co.uk>
Sender: r-sig-geo-bounces at r-project.orgDate: Wed, 20 Jun 2012 17:40:31
To: r-sig-geo at stat.math.ethz.ch<r-sig-geo at stat.math.ethz.ch>
Reply-To: Juliane Struve <juliane_struve at yahoo.co.uk>
Subject: [R-sig-Geo] plot nearest neighbor links
Dear list,
I would like to plot the links that dnearneigh() identifies.
Space <- matrix(data = 1, nrow = 10, ncol = 10)
Space[1,] <- NA
Space[nrow(Space),] <- NA
Space[,1] <- NA
Space[,ncol(Space)] <- NA
WaterRow <- row(Space)
WaterCol <- col(Space)
WaterXY <- cbind(X=WaterRow[Space==1], Y=WaterCol[Space==1])
library(spdep)
WaterXY <- na.omit(WaterXY)
WaterNB <- dnearneigh(WaterXY, 0, 1)
res <- listw2sn(nb2listw(WaterNB))[,1:2]
as.matrix(res)
I have found an older post on a related topic that shows an example of what I would like to do:
example(read.gal)
# to get an nb object
us48.q
us48.q[1:2]
res <- listw2sn(nb2listw(us48.q))[,1:2]
res[1:9,]
str(res)
I have managed to retrieve the links using as.matrix(res), but I can't get the plot of nodes and links to appear.
Could someone help out ?
Thank you very much in advance,
Juliane
[[alternative HTML version deleted]]
More information about the R-sig-Geo
mailing list