[英]How to change color of label edges on diagrammer graphs and avoid overlapping?. R
如何更改Diagrammer图表上边缘标签的颜色?
玩具示例:
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编辑结果。
这是您问题的可能解决方案。
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)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.