簡體   English   中英

如何更改圖表圖形上標簽邊緣的顏色並避免重疊? [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)

在此處輸入圖片說明

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM