How to rearrange a chart in R

I updated my diagrammerto version 0.9.0 and started to visualize another diagram from the same data. Now my data frame is as follows:

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

The rest of the code is as follows:

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)

When the code is used, I get this diagram:

enter image description here

When it should look like this:

enter image description here

+3
source share
2 answers

Create a graph with attr_theme = NULL:

g <- create_graph(nodes_df=nodes, edges_df=edges, attr_theme = NULL)

In the current version, DiagrammeR sets the global attribute layoutto neato. You can check this with:

g <- create_graph(nodes_df=nodes, edges_df=edges)
get_global_graph_attrs(g)

#           attr      value attr_type
# 1       layout      neato     graph
# 2  outputorder edgesfirst     graph
# 3     fontname  Helvetica      node
# 4     fontsize         10      node
# 5        shape     circle      node
# 6    fixedsize       true      node
# 7        width        0.5      node
# 8        style     filled      node
# 9    fillcolor  aliceblue      node
# 10       color     gray70      node
# 11   fontcolor     gray50      node
# 12         len        1.5      edge
# 13       color     gray40      edge
# 14   arrowsize        0.5      edge

You can also set these attributes using set_global_graph_attrsafter creating the chart object.

+4
source

You can also set these attributes using set_global_graph_attrsafter creating the chart object.

:

set_global_graph_attrs(
    graph = graph,
    attr = c("layout", "rankdir", "splines"),
    value = c("dot", "LR", "false"),
    attr_type = c("graph", "graph", "graph"))

render_graph(graph2)

- , .

magrittr %>%, .

graph1 <-
   create_graph(
      nodes_df = ndf,
      edges_df = edf) %>%
   set_global_graph_attrs(
      attr = c("layout", "rankdir", "splines"),
      value = c("dot", "LR", "false"),
      attr_type = c("graph", "graph", "graph"))

node, : http://www.graphviz.org/doc/info/attrs.html#h:uses

+2

Source: https://habr.com/ru/post/1669081/


All Articles