[R] Discontinuous graph

Steve Lianoglou mailinglist.honeypot at gmail.com
Mon Nov 16 18:55:12 CET 2009


Hi Tim,

On Nov 16, 2009, at 12:40 PM, Tim Smith wrote:

> Hi,
> I wanted to make a graph with the following table (2 rows, 3 columns):
> a b c
> x 1 3 5
> y 5 8 6
> The first column represents the start cordinate, and the second  
> column contains the end cordinate for the x-axis. The third column  
> contains the y-axis co-ordinate. For example, the first row in the  
> matrix above represents the points (1,5),(2,5), (3,5). How would I  
> go about making a discontinuous graph ?

What is it that you want to do with this graph? Or, how do you want  
represent it?

Do you just want to generate the sequence of points? I'm guessing not,  
but here's code to do that and stores into the edge.pairs matrix  
(first row is the x-values, 2nd row is the y-value of the same point)

data.matrix <- matrix(c(1,3,5,5,8,6), nrow=2, byrow=T)
points <- apply(data.matrix, 1, function(row) unlist(t(expand.grid(row 
[1]:row[2], row[3]))))
edge.pairs <- do.call(cbind, points)

It should be pretty straightforward to convert edge.paris into an  
adjacency matrix, if you like. Also, if you're thinking about using R  
to work with graphs, I'd suggest checking out the igraph pacakge.

Hope that helps,

-steve

--
Steve Lianoglou
Graduate Student: Computational Systems Biology
   |  Memorial Sloan-Kettering Cancer Center
   |  Weill Medical College of Cornell University
Contact Info: http://cbio.mskcc.org/~lianos/contact




More information about the R-help mailing list