问题
I have a nice graph with DiagrammeR in R studio, but the nodes are too clustered togather. I have searched everywhere but I cannot find a way of increasing the distance between them. Can I be shown?
Here is my code:
library(magrittr)
library(DiagrammeR)
# Create a simple NDF
nodes <- create_nodes(nodes = c("Index", "Surveillance", "Intervention","Lost"),
label = TRUE,
fontsize=55,
type = "lower",
style = "filled",
color = "aqua",
shape = c("circle", "circle",
"rectangle", "rectangle"),
data = c(30.5, 2.6, 9.4, 2.7))
edges <- create_edges(from = c("Index", "Surveillance","Surveillance","Intervention", "Surveillance", "Index" ),
to = c("Surveillance", "Intervention","Surveillance","Intervention", "Lost", "Lost"),
rel = c(99, 6.7, 99, 99, 27, 22),
arrowhead = rep("normal", 6),
color = c("green", "green", "red", "red", "red", "red"))
graph <-
create_graph(
nodes_df = nodes,
edges_df = edges,
graph_attrs <-
c("layout = dot","overlap = FALSE","outputorder = edgesfirst"),
node_attrs <-
c("shape = circle",
"fixedsize = TRUE",
"width = 100",
"penwidth = 1",
"color = DodgerBlue",
"style = filled",
"fillcolor = Aqua",
"alpha_fillcolor = 0.5",
"fontname = Helvetica",
"fontcolor = Black"),
edge_attrs = "color = gray20")
# View the graph
render_graph(graph,layout=constant,output="visNetwork")
回答1:
You could just set the length for the arrows between different nodes:
edges <- create_edges(from = c("Index", "Surveillance","Surveillance","Intervention", "Surveillance", "Index" ),
to = c("Surveillance", "Intervention","Surveillance","Intervention", "Lost", "Lost"),
rel = c(99, 6.7, 99, 99, 27, 22),
arrowhead = rep("normal", 6),
color = c("green", "green", "red", "red", "red", "red"),
length = c(200,200,50,50,200,200))
Or you could define a precise spot for each node:
nodes <- create_nodes(nodes = c("Index", "Surveillance", "Intervention","Lost"),
label = TRUE,
fontsize = 55,
type = "lower",
style = "filled",
color = "aqua",
shape = c("circle", "circle",
"rectangle", "rectangle"),
data = c(30.5, 2.6, 9.4, 2.7),
x = c(-80,80,-80,80),
y = c(-80,80,80,-80))
来源:https://stackoverflow.com/questions/38055696/how-to-increase-distance-between-nodes-in-diagrammer-r