在 R 中使 visnetwork 图的边缘变直
Making the edges of the visnetwork diagram straight in R
给定的 visNetwork 脚本创建了如下快照中的 visNetwork 图。我的问题是,如果您看到第一个和第二个节点,则两者之间的边缘是弯曲的。有没有一种方法可以在不改变边缘长度的情况下使边缘笔直。附上快照供参考,请帮忙。
library(visNetwork)
nodes <- data.frame(id = 1:10,color = c(rep("blue",6), rep("red",3),
rep("green",1)))
edges <- data.frame(from = c(1,2,3,3,4,5,6,7,8,9), to =
c(2,3,4,8,5,6,7,8,9,10),length = c(2,1,1,1,1,1,1,1,1,1))
nodes = data.frame(nodes, level = edges$from)
visNetwork(nodes, edges, height = "500px", width = "100%") %>%
visOptions(highlightNearest = list(enabled = T, degree = 2, hover = T)) %>%
visOptions(highlightNearest = F, nodesIdSelection = F, width = 500, height =
500,autoResize = F) %>%
visEdges(smooth = T) %>%
addFontAwesome() %>% visHierarchicalLayout(edgeMinimization = T,
blockShifting = T , levelSeparation = 89 ) %>%
visEdges(shadow = TRUE,
arrows =list(to = list(enabled = TRUE, scaleFactor = 2)),
color = list(color = "black", highlight = "red")) %>%
visLayout()
只需将 visEdges()
的 smooth=
参数设置为 FALSE
:visEdges(smooth = FALSE)
library(visNetwork)
nodes <- data.frame(id = 1:10,color = c(rep("blue",6),
rep("red",3),
rep("green",1)))
edges <- data.frame(from = c(1,2,3,3,4,5,6,7,8,9),
to = c(2,3,4,8,5,6,7,8,9,10),
length = c(2,1,1,1,1,1,1,1,1,1))
nodes <- data.frame(nodes, level = edges$from)
visNetwork(nodes, edges,
height = "500px", width = "100%",
main = "Straight Edges") %>%
visHierarchicalLayout(edgeMinimization = T,
blockShifting = T ,
levelSeparation = 89 ) %>%
visEdges(
# =========================
smooth = FALSE, # ========================= straight edges
# =========================
shadow = TRUE,
arrows =list(to = list(enabled = TRUE, scaleFactor = 2)),
color = list(color = "black", highlight = "red")
)
给定的 visNetwork 脚本创建了如下快照中的 visNetwork 图。我的问题是,如果您看到第一个和第二个节点,则两者之间的边缘是弯曲的。有没有一种方法可以在不改变边缘长度的情况下使边缘笔直。附上快照供参考,请帮忙。
library(visNetwork)
nodes <- data.frame(id = 1:10,color = c(rep("blue",6), rep("red",3),
rep("green",1)))
edges <- data.frame(from = c(1,2,3,3,4,5,6,7,8,9), to =
c(2,3,4,8,5,6,7,8,9,10),length = c(2,1,1,1,1,1,1,1,1,1))
nodes = data.frame(nodes, level = edges$from)
visNetwork(nodes, edges, height = "500px", width = "100%") %>%
visOptions(highlightNearest = list(enabled = T, degree = 2, hover = T)) %>%
visOptions(highlightNearest = F, nodesIdSelection = F, width = 500, height =
500,autoResize = F) %>%
visEdges(smooth = T) %>%
addFontAwesome() %>% visHierarchicalLayout(edgeMinimization = T,
blockShifting = T , levelSeparation = 89 ) %>%
visEdges(shadow = TRUE,
arrows =list(to = list(enabled = TRUE, scaleFactor = 2)),
color = list(color = "black", highlight = "red")) %>%
visLayout()
只需将 visEdges()
的 smooth=
参数设置为 FALSE
:visEdges(smooth = FALSE)
library(visNetwork)
nodes <- data.frame(id = 1:10,color = c(rep("blue",6),
rep("red",3),
rep("green",1)))
edges <- data.frame(from = c(1,2,3,3,4,5,6,7,8,9),
to = c(2,3,4,8,5,6,7,8,9,10),
length = c(2,1,1,1,1,1,1,1,1,1))
nodes <- data.frame(nodes, level = edges$from)
visNetwork(nodes, edges,
height = "500px", width = "100%",
main = "Straight Edges") %>%
visHierarchicalLayout(edgeMinimization = T,
blockShifting = T ,
levelSeparation = 89 ) %>%
visEdges(
# =========================
smooth = FALSE, # ========================= straight edges
# =========================
shadow = TRUE,
arrows =list(to = list(enabled = TRUE, scaleFactor = 2)),
color = list(color = "black", highlight = "red")
)