[R] Point patterns and igraph

Gábor Csárdi csardi at rmki.kfki.hu
Tue Sep 8 08:52:53 CEST 2009


Juanita,

On Tue, Sep 8, 2009 at 8:02 AM, juanita choo<juanitachoo at gmail.com> wrote:
> Hi,
>
> I have a data set consisting of the x and y coordinate locations of 1600
> points. I would like to generate a graph using the functions in igraph.
> However the graph making functions in igraph requires the data to be in the
> form of an adjacency matrix.

well, this is not quite true, there are quite a number of formats
igraph can create graphs from, see graph.adjlist(), graph.formula(),
graph.data.frame() or graph(). But you are right that
graph.adjacency() is probably the easiest for you.

> I'd like some advice on how to convert my point
> pattern to an adjacency matrix or functions out there that would do it
> directly. I've only gotten as far as obtaining the distance matrix using
> dist().

You are almost there, then. You can filter your distance matrix if you
like, and then create a weighted graph from the remaining edges:

co <- cbind(rnorm(10), rnorm(10))
D <- as.matrix(dist(co))
D[ D > 2 ] <- 0
G <- graph.adjacency(D, mode="undirected", weighted=TRUE)

Gabor

> Thanks for the help.
>
> Best,
> Juanita
>
> --
> Juanita Choo
> Graduate Student
> Section of Integrative Biology
> University of Texas at Austin
> 1 University Station Stop
> TX 78712
> +1 512 471 5773
>
>
>
> --
> Juanita Choo
> Graduate Student
> Section of Integrative Biology
> University of Texas at Austin
> 1 University Station Stop
> TX 78712
> +1 512 471 5773
>
>        [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



-- 
Gabor Csardi <Gabor.Csardi at unil.ch>     UNIL DGM




More information about the R-help mailing list