Skip to content

Discontinuous graph

6 messages · David Winsemius, Steve Lianoglou, Baptiste Auguie +1 more

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

            
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
#
On Nov 16, 2009, at 12:40 PM, Tim Smith wrote:

            
coords <- read.table(textConnection("a b c
  x 1 3 5
  y 5 8 6"), header=TRUE)

  plot(NULL, NULL, xlim = c(min(coords$a)-.5, max(coords$b)+.5),  
ylim=c(min(coords$c)-.5, max(coords$c)+.5)  )
  apply(coords, 1, function(x) segments(x0=x[1],y0= x[3], x1= x[2],  
y1=x[3]) )
#
On Nov 16, 2009, at 12:58 PM, David Winsemius wrote:

            
Oh, *that* kind of graph!

... my high-school English teacher once said that "all communication  
is miscommunication" because we each interpret things according to our  
own experiences, etc ... I guess that goes to show:

   (i) me that he was right (once again);
   (ii) you what I've been working on lately :-)

Sorry for the line-noise,

-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
#
Hi,

An alternative with ggplot2,

library(ggplot2)

ggplot(data=coords) +
  geom_segment(aes(x=a, xend=b, y=c, yend=c))


HTH,

baptiste

2009/11/16 David Winsemius <dwinsemius at comcast.net>:
1 day later