我想将节点的位置固定在 (1,0)、(0,1)、(-1,0)、(0,-1) 和 (0,0)。但是,它不起作用并且我的 Java 知识为零(似乎 here 是有关 Java 代码的问题)。
有人可以帮忙吗?下面是一个例子:
require(visNetwork, quietly = TRUE)
nodes <- data.frame(id = 1:5)
# x = c(1, 0, -1, 0, 0),
# y = c(0, 1, 0, -1, 0))
edges <- data.frame(from = c(1,2), to = c(1,3))
visNetwork(nodes, edges, width = "100%") %>%
visNodes(x = c(1, 0, -1, 0, 0),
y = c(0, 1, 0, -1, 0), fixed = TRUE, physics = TRUE) %>%
visOptions(highlightNearest = TRUE) %>%
visInteraction(navigationButtons = TRUE, dragNodes = FALSE,
dragView = FALSE, zoomView = FALSE) %>%
visEdges(arrows = 'from')
最佳答案
你可以做
coords <- matrix(ncol=2, byrow=T, data=c(
1,0,
0,1,
-1,0,
0,-1,
0,0))
opts <- . %>% visOptions(highlightNearest = TRUE) %>%
visInteraction(navigationButtons = TRUE, dragNodes = FALSE,
dragView = FALSE, zoomView = FALSE) %>%
visEdges(arrows = 'from')
visNetwork(nodes, edges, width = "100%") %>%
visIgraphLayout(layout = "layout.norm", layoutMatrix = coords) %>%
opts
或者
nodes$x <- c(1, 0, -1, 0, 0)*100
nodes$y <- c(0, 1, 0, -1, 0)*100
visNetwork(nodes, edges, width = "100%") %>%
visNodes(fixed = TRUE) %>%
opts
如有必要,使用
coords[,2] <- coords[,2]*-1
翻转垂直轴。关于r - 如何在R中的visNetwork包中指定节点的位置,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/47630378/