2017-02-10 11 views
3

diagrammerをバージョン0.9.0にアップデートし、同じデータから別の図を描画し始めました。私のデータフレームは、次のようになります。図を並べ替える方法R

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

コードの残りの部分は次のようになります。

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) 

コードが使用されている場合、私は、この図を得る:

enter image description here

それを次のようになります。

enter image description here

答えて

4

attr_theme = NULLでグラフを作成します。現在のバージョンで

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

は、ダイアグラマは格好いいにグローバル属性layoutを設定します。 あなたがでこれを確認することができます。

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 

ます。また、グラフオブジェクトを作成した後set_global_graph_attrsでこれらの属性を設定することができます。

+0

私はそのような他のattr_theme =サーコ、などのオプションやtwopiを使用して試してみたが、それは動作しません。どうしたらいいですか? @ larnsceの解決策が私のために働かない – skan

2

グラフオブジェクトを作成した後で、これらの属性をset_global_graph_attrsに設定することもできます。

私は上記を試してみましたが、次の操作を行ったときに失敗しました:

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")) 

ドキュメントは、ここでは属性:http://www.graphviz.org/doc/info/attrs.html#h:uses

関連する問題