[R] Rgraphviz: How to control the colours of edges in a graph
Gabor Grothendieck
ggrothendieck at gmail.com
Thu Jul 6 03:33:20 CEST 2006
Try this:
eAttrs <- list(color = c("A~B" = "green", "B~C" = "green", "C~D" = "yellow",
"A~C" = "yellow"))
plot(G, "neato", nodeAttrs = nAttrs, edgeAttrs = eAttrs)
More info via:
vignette("Rgraphviz")
On 7/5/06, Søren Højsgaard <Soren.Hojsgaard at agrsci.dk> wrote:
> 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 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
>
More information about the R-help
mailing list