Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I color nodes of a graphNEL graph?

I'm using graphNEL objects from gRbase and Rgraphviz for plotting and would like to color the nodes of the graph in different (specified) colors when plotting. For example, how could I plot this graph with a and b in blue and c and d in red?

library(Rgraphviz)
library(gRbase)
mygraph = dag(~a:c + b:c + b:d)
plot(mygraph)

enter image description here

like image 269
Corvus Avatar asked Mar 10 '13 12:03

Corvus


1 Answers

This should work ;

nAttrs<-list()
nAttrs$color <- c(a = "blue", b = "blue", c = "red", d = "red")
plot(g1, nodeAttrs = nAttrs)

see also getDefaultAttrs() to get all the graph attributes with default values.

like image 99
agstudy Avatar answered Nov 02 '22 09:11

agstudy