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"
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)
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With