[R] Do you know if you can map a large minimum spanning tree in R?

Roger Bivand Roger.Bivand at nhh.no
Thu Aug 19 09:36:53 CEST 2004

> Thanks Mike.
> My data has longitude and latitude coords and I used distAB {clim.pact}
then mst {ape} to calculate my minimum spanning tree.  The nodes are
telecoms sites from all over Australia.  My goal is to determine the
minimum cost of linking them via cabling, and I'm starting by
> calculating the distance "as the crow flies", but will probably
> eventually need to calculate the rectilinear distances also.
> I am a very newbie user of R, but have had experience with other
stats/programming software such as SAS, however no longer have access to
SAS so I've turned to R.  I also have tried using MapInfo with the data
exported from R, but have found that not so intuitive to learn on the
> Back to R - I'm using W2K, and have managed to graph the tree using
plot(mdist,graph="nsca") where mdist is the output matrix from my mst
command, however this is not terribly map-like, so I'm looking for a
better display that can be embedded in a document.
> Any assistance gratefully received!

One possibility is to use the fact that mst() function returns a 0/1
matrix exactly like spatial weights matrices used in the spdep package:

> X <- matrix(runif(n*50), 50, n)
> d <- dist(X)
> M <- mst(d)
> library(spdep)
> M.nb <- mat2listw(M)$neighbours
> plot(M.nb, X)

The plot.nb() function then plots the graph by joining points defined as
neighbours, use the add=TRUE argument to overplot on a base map. The nb
object can also be manipulated a little, like subsetting, if that is any
use. The idea is to convert the 0/1 matrix to a list with vectors of
neighbours' IDs for each point, rather than store the whole matrix.
Contact me off-list if you need more details. (nbdists() retrieves the
distances on the graph too).

> Fiona.
>> Fiona Wade
>> Project Manager
>> F&A
>> Telstra Corporation Limited
>> Tel: 03 9634 5674
>> Fax: 03 9634 2874
>> Email: fiona.m.wade at team.telstra.com
>> The information contained in this e-mail message may be confidential.
> If you are not the intended recipient, any use of, interference with,
disclosure or copying of this material is unauthorised and prohibited.
If you have received this message in error, please notify me by reply
e-mail and then delete the message.
> -----Original Message-----
> From: Michael Sumner [mailto:mdsumner at utas.edu.au]
> Sent: Thursday, 19 August 2004 10:18 AM
> To: Briggs, Meredith M; r-help at stat.math.ethz.ch
> Cc: Wade, Fiona M
> Subject: Re: [R] Do you know if you can map a large minmum spanning tree
in R?
> At 09:47 AM 8/19/2004, Briggs, Meredith M wrote:
>>         Do you know
if you can map in R?
>>         I have my minimum spanning tree, but as there are 1371 nodes
> (all
>> over Australia) I'd like to be able to "graph" them as they actually
would be on the map.
>>Do you know if this is possible?
> You can certainly "map" in R.  Depending on the coordinate system of your
> data . . .
> but, e.g. - if it's lat/lon - perhaps the easiest way is to install the
"maps" package and you can add the continental outlines to an existing
> ## display nodes code here . . .
> library(maps)
> map('world',add=T,xlim=c(109,157),ylim=c(-47,-7))
> There are plenty of other options, if you have your own map data (or want
> to use another source).  Feel free to provide more detail about your
current plotting methods and coordinate system.
> Also, the package "mapdata" contains a high reso
> lution continental
> dataset
> -"worldHires"
> Hope that helps, Mike.
> ###############################################
> Michael Sumner - PhD. candidate
> Maths and Physics (ACE CRC & IASOS) and Zoology (AWRU)
> University of Tasmania
> Private Bag 77, Hobart, Tas 7001, Australia
> Phone: 6226 1752
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide!
> http://www.R-project.org/posting-guide.html

Roger Bivand
NHH, Breiviksveien 40, N-5045 Bergen, Norway

More information about the R-help mailing list