0

I have diagram and want to add variety of colors to the nodes, so I added this code line from grviz that change node color from the value he has node = "[fillcolor = red]Canis" but it didn't change anything in diagram.

The rest code for diagram:

df <- data.frame(col1 = c( "Cat", "Dog", "Bird"),
         col2 = c( "Feline", "Canis", "Avis"), 
         stringsAsFactors=FALSE)

uniquenodes <- unique(c(df$col1, df$col2))
library(DiagrammeR)
nodes <- create_node_df(n=length(uniquenodes), nodes = seq(uniquenodes), type="number", label=uniquenodes, nodes = "[fillcolor = red]Canis")
edges <- create_edge_df(from=match(df$col1, uniquenodes), to=match(df$col2, uniquenodes), rel="related")
g <- create_graph(nodes_df=nodes, edges_df=edges, attr_theme = NULL)
render_graph(g)
Deividas Kiznis
  • 431
  • 1
  • 6
  • 20
  • Where did you get the `nodes` argument from `create_node_df`? I looked at `?create_node_df`, tried `nodes <- create_node_df(n=length(uniquenodes), nodes = seq(uniquenodes), type="number", label=uniquenodes, fillcolor = sample(colours(), length(uniquenodes)))` and it seems to work in terms of changing fill colors... – lukeA Mar 18 '17 at 16:53
  • I don't want just to change fill color I want that only node with `Canis` name be red – Deividas Kiznis Mar 18 '17 at 17:16
  • 2
    `cols <- setNames(rep("green", length(uniquenodes)), uniquenodes);cols["Canis"]<-"red"` and `fillcolor=cols`? – lukeA Mar 18 '17 at 17:38
  • It works very nicely but I it doesn't work with `attr_theme = NULL`. What can you suggest? – Deividas Kiznis Mar 18 '17 at 18:07
  • Well, I suggest you explain where `attr_theme=NULL` comes into play because I don't see it anywhere in your code. To do so, it's probably best to again edit your original post and add the code that you got so far (instead of e.g. loading comments with code, which isn't as easy to follow). That way, everyone is on the same page again. – lukeA Mar 18 '17 at 20:00
  • The `attr_theme = NULL` set in what theme(style) diagrams are being rendered. This line turn off all theme(style) in diagram (I edited to my code) – Deividas Kiznis Mar 18 '17 at 20:29

0 Answers0