我的代码应该用很少的额外颜色渲染图表,但是当使用代码时,我看不到任何颜色
df <- data.frame(col1 = c( "Cat", "Dog", "Bird"),
col2 = c( "Feline", "Canis", "Avis"),
stringsAsFactors=FALSE)
uniquenodes <- unique(c(df$col1, df$col2))
library(DiagrammeR)
cols <- setNames(rep("green", length(uniquenodes)), uniquenodes);cols["Canis"]<-"red"
nodes <- create_node_df(n=length(uniquenodes), nodes = seq(uniquenodes), type="number", label=uniquenodes, fillcolor=cols)
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)