I would like to decrease the distance between nodes in DiagrammeR
R package. I am aware that is a similar question here: How to increase distance between nodes in DiagrammeR R. However, such a solution is not working in the current DiagrammeR
version (1.0.6.1). I have a found in the manual a given solution:
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")
As pointed in the code above, the len
parameter is supposed to give different distances to the two different edges (i.e. nodes 1-2 to 2-3). However the resulting diagram don´t have different edge distances. It prints as follows:
I am aware that in the dot language (i.e. Graphviz) the distance between nodes is governed by minlen
parameter. However, minlen
is not a parameter in the edge_aes()
. I even tried to modify the source code of the edge_aes()
to include a minlen
parameter, but it did not work as well:
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]
}
Any ideas to make different node distances work in a DiagrammeR
package?