I'm trying create image of diagrammer graph but it creates blank files instead. My data frame:
df <- data.frame(col1 = c("Cat", "Dog", "Bird"),
col2 = c("Feline", "Canis", "Avis"),
stringsAsFactors = FALSE)
The rest of code:
png("C:\\tmp\\anim.png")
uniquenodes <- unique(c(df$col1, df$col2))
library(DiagrammeR)
nodes <- create_node_df(n=length(uniquenodes), nodes = seq(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)
dev.off()
First install DiagrammeRsvg
and rsvg
packages. At the end of code add thees lines:
export_graph(graph_name,
file_name = "pic.png",
file_type = "png")
With this you can create not only png
image and pdf
also.