6

I currently have R version 3.2.2 with DiagrammeR R package. I get these two errors when trying to run the following code:

library(DiagrammeR)
nodes <- create_nodes(nodes = seq(uniquenodes), 
                      type = "number", 
                      label = uniquenodes)

Error: could not find function "create_nodes"

edges <- create_edges(from = match(df$col1, uniquenodes), 
                      to = match(df$col2,uniquenodes), 
                      rel = "related")

Error: could not find function "create_edges"

rosscova
  • 5,430
  • 1
  • 22
  • 35
Deividas Kiznis
  • 431
  • 1
  • 6
  • 20
  • 2
    please run `packageVersion("DiagrammeR")`. The API changed recently, and if you are using `DiagrammeR` 0.9.0, you will need to switch to `create_node_df` (I think) – Benjamin Feb 07 '17 at 20:35
  • I use 0.9.0 version and used code line this: `nodes<-create_node_df(nodes=seq...` but still doesn't work – Deividas Kiznis Feb 07 '17 at 21:18

2 Answers2

8

The code below should be compatible with DiagrammeR 0.9.0. The graph appears to have a different appearance than the one generated in DiagrammeR creates "wrong" diagram in R. I haven't played with render_graph in 0.9.0 very much, so am not yet sure how to get the earlier appearance.

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

uniquenodes

library(DiagrammeR)

nodes <- create_node_df(n=length(uniquenodes), 
                        type="number", 
                        label=uniquenodes)
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)
render_graph(g)
Community
  • 1
  • 1
Benjamin
  • 16,897
  • 6
  • 45
  • 65
1

I haven't played with render_graph in 0.9.0 very much, so am not yet sure how to get the earlier appearance.

The different appearance comes from the argument attr_theme in function create_graph, which is set to "default". Setting it to NULL provides brings back the appearance, however, this can be further adjusted by using function set_global_graph_attributes, which for me only worked in combination with magrittr:%>% as described here: https://stackoverflow.com/a/42676248/6816220

Community
  • 1
  • 1
larnsce
  • 103
  • 8