2017-11-24 9 views
0

Diagrammerグラフでエッジのラベルの色を変更するにはどうすればよいですか?ダイアグラムグラフ上のラベルエッジの色を変更し、オーバーラップを避ける方法は? R

エッジの色自体は変更できますが、テキストのラベルは変更できません。 enter image description here

玩具例:

niv <- c("A","B","C","D","E","X","Y") 
from <- c("A","A","A","A","B","C","D","E", "X", "B") 
to <- c("B","C","D","E","X","X","Y","Y","Y", "C") 
temp <- data.table(from=factor(from, levels=niv), 
to=factor(to,levels=niv), col=c(rep("blue",5), rep("black",5))) 

nodes <- create_node_df( n=length(niv), label=niv, width=0.3) 
edges <- create_edge_df(from = temp$from, to = temp$to, 
rel = "leading_to", label=temp$from, color=temp$col) 
graph <- create_graph( nodes_df = nodes, edges_df = edges) 
render_graph(graph) 

また、自動的にエッジと重なったエッジのラベルを回避する方法を知っていいのだろうか? 現時点では、結果をInkscapeで編集する必要があります。

答えて

1

ここにあなたの質問に対する解決策があります。

library(DiagrammeR) 
library(data.table) 
niv <- c("A","B","C","D","E","X","Y") 
from <- c("A","A","A","A","B","C","D","E", "X", "B") 
to <- c("B","C","D","E","X","X","Y","Y","Y", "C") 
temp <- data.table(from=factor(from, levels=niv), 
to=factor(to,levels=niv), col=c(rep("blue",5), rep("black",5))) 

nodes <- create_node_df(n=length(niv), label=niv, width=0.3) 
# Add a vector of colors for fontcolor 
edges <- create_edge_df(from=temp$from, to=temp$to, 
     rel="leading_to", label=temp$from, color=temp$col, 
     fontcolor=temp$col) 

graph <- create_graph(nodes_df = nodes, edges_df = edges) 

# Delete the default "layout" graph attribute and 
# set direction of graph layout 
graphAttr <- get_global_graph_attrs(graph) 
graphAttr <- rbind(graphAttr[-1,], 
        c("rankdir", "LR", "graph")) 

graph <- set_global_graph_attrs(graph, 
     attr = graphAttr$attr, 
     value = graphAttr$value, 
     attr_type = graphAttr$attr_type) 

render_graph(graph) 

enter image description here

+0

私はエッジよりも同じ色をそれぞれ番号を持っていると思います、それは可能ですか? – skan

+0

@skan私は自分の答えを更新しました。私はあなたの問題にエッジラベルの色を使って解決策を見つけました。 –

関連する問題