[R] Rgraphviz: How to control the colours of edges in a graph

From: Søren Højsgaard <Soren.Hojsgaard_at_agrsci.dk>
Date: Thu 06 Jul 2006 - 10:21:43 EST


Using Rgraphviz, I draw the undirected graph with vertices A,B,C and D and edges A:B, B:C, C:D, D:A, A:C. I want the vertices A and B to be red and C and D to be blue. The problem is the following: I want the edges A:B and B:C to be green and the edges C:D and C:A to be yellow, while the edge A:C can have the default colour black. I assume that I have to specify this using the edgeAttrs-argument in the plot function, but I can't figure out how. Can anyone help? Thanks.
Søren  

Code for drawing the graph:  

   library(Rgraphviz)
   V <- c("A","B","C","D")
   E <- list(c("A","B"),c("B","C"),c("C","D"),c("D","A"),c("A","C"))    Eidx <- lapply(E, match, V)
   edL <- vector("list", length=length(V))    names(edL) <- V
   for (i in 1:length(Eidx)){

     tmp <- Eidx[[i]]
     print(tmp)
     edL[[tmp[1]]]$edges <- c(edL[[tmp[1]]]$edges, tmp[2])
     edL[[tmp[2]]]$edges <- c(edL[[tmp[2]]]$edges, tmp[1])
   }
   G <- new("graphNEL", nodes=V, edgeL=edL)    nAttrs <- list()
   nAttrs$fillcolor <- c("red","red","blue","blue")    names(nAttrs$fillcolor) <- V

   plot(G, "neato",nodeAttrs=nAttrs)

R-help@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 Received on Thu Jul 06 10:26:08 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Thu 06 Jul 2006 - 12:16:35 EST.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.