如何更改图表上标签边缘的颜色并避免重叠? R
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)
如何更改 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)