我想减少 DiagrammeR
R 包中节点之间的距离。我知道这里有一个类似的问题:How to increase distance between nodes in DiagrammeR R。但是,这种解决方案在当前的 DiagrammeR
版本 (1.0.6.1) 中不起作用。我在手册中找到了一个给定的解决方案:
library(DiagrammeR)
graph <-
create_graph() %>%
add_path(
n = 3,
type = "path",
edge_aes = edge_aes(
style = "solid",
color = c("yellow", "blue"),
len= c(10, 0.2), ## Parameter to change edge distance
))
render_graph(graph, layout="tree")
正如上面的代码所指出的,len
参数应该为两条不同的边(即节点 1-2 到 2-3)提供不同的距离。然而,生成的图表没有不同的边缘距离。它打印如下:
我知道在点语言(即 Graphviz)中,节点之间的距离由 minlen
参数控制。但是,minlen
不是 edge_aes()
中的参数。我什至尝试修改 edge_aes()
的源代码以包含 minlen
参数,但效果不佳:
edge_aesM <- function (style = NULL, penwidth = NULL, color = NULL, arrowsize = NULL,
arrowhead = NULL, arrowtail = NULL, fontname = NULL, fontsize = NULL,
fontcolor = NULL, len = NULL, tooltip = NULL, URL = NULL,
label = NULL, labelfontname = NULL, labelfontsize = NULL,
labelfontcolor = NULL, labeltooltip = NULL, labelURL = NULL,
edgetooltip = NULL, edgeURL = NULL, dir = NULL, headtooltip = NULL,
headURL = NULL, headclip = NULL, headlabel = NULL, headport = NULL,
tailtooltip = NULL, tailURL = NULL, tailclip = NULL, taillabel = NULL,
tailport = NULL, decorate = NULL, minlen=NULL)
{
attr_values <- list(style = style, penwidth = penwidth, color = color,
arrowsize = arrowsize, arrowhead = arrowhead, arrowtail = arrowtail,
fontname = fontname, fontsize = fontsize, fontcolor = fontcolor,
len = len, tooltip = tooltip, URL = URL, label = label,
labelfontname = labelfontname, labelfontsize = labelfontsize,
labelfontcolor = labelfontcolor, labeltooltip = labeltooltip,
labelURL = labelURL, edgetooltip = edgetooltip, edgeURL = edgeURL,
dir = dir, headtooltip = headtooltip, headURL = headURL,
headclip = headclip, headlabel = headlabel, headport = headport,
tailtooltip = tailtooltip, tailURL = tailURL, tailclip = tailclip,
taillabel = taillabel, tailport = tailport, decorate = decorate,
minlen=minlen)
non_null_attrs <- 1:length(attr_values) %>% purrr::map_chr(.f = function(x) {
if (!is.null(attr_values[[x]])) {
attr_values[x] %>% names()
}
else {
NA
}
})
non_null_attrs <- non_null_attrs[which(!is.na(non_null_attrs))]
attr_values[non_null_attrs]
}
有什么想法可以让不同的节点距离在 DiagrammeR
包中工作吗?