问题描述
在以下可见网络中,我有 2 组节点。通过在生成 layput_as_tree
后访问节点位置,我已将 2 组节点分为左侧和右侧。然后使用 visEvents
在节点组周围绘制一个椭圆,以显示更多定义为 2 个单元结构的分隔。
我想控制节点位置的排列。例如,一些节点需要在椭圆的边界上,一些在非常中心,一些分散在周围。想知道是否有一种方法可以根据列为特定节点分配位置,同时避免重叠?
可重现的例子
require(shiny)
require(visNetwork)
server <- function(input,output) {
output$network <- visNetwork::renderVisNetwork({
edges <- data.frame(
from = sample(1:10,8),to = sample(1:10,label = paste("interaction type",1:8),length = c(100,500),width = c(4,1),arrows = c("to","from","middle","middle;to"),dashes = c(TRUE,FALSE),title = paste("interaction name",smooth = c(FALSE,TRUE),shadow = c(FALSE,TRUE,FALSE,TRUE)
)
nodes <- data.frame(
id = 1:10,group = c("A","B"),label = paste("Node",1:10),position = c("center","center","edge","edge")
shape = "ellipse"
)
# save the graph in variable
g <-
visNetwork::visNetwork(nodes,edges,height = "500px",width = "100%") %>%
visNetwork::visIgraphLayout(layout = "layout_as_tree")
# access the x and y co-ordinates to arrange the groups
coords <- g$x$nodes %>%
dplyr::mutate(x = abs(x)) %>%
dplyr::mutate(y = abs(y)) %>%
dplyr::mutate(x = ifelse(group %in% "A",-x,x)) %>%
dplyr::select(x,y) %>%
as.matrix()
#' replot the network with the new co-ordinates
visNetwork::visNetwork(nodes,width = "100%") %>%
visNetwork::visIgraphLayout(
layout = "layout.norm",layoutMatrix = coords,randomSeed = 1,smooth = T
) %>%
visNetwork::visEvents(type = "on",beforeDrawing = "function(ctx) {
ctx.fillStyle = 'rgba(255,255,0.1)';
ctx.ellipse(-180,25,150,280,2 * Math.PI);
ctx.fill();
ctx.fillStyle = 'rgba(64,0.1)';
ctx.ellipse(180,2 * Math.PI);
ctx.fill();
}")
})
}
ui <- shiny::fluidPage(
visNetwork::visNetworkOutput("network",width = "1000px",height = "700px"
)
)
shiny::shinyApp(ui = ui,server = server)
我正在寻找可以控制节点位置到椭圆上特定位置的东西。例如
nodes_at_edges_grpA <- c(1,5,9)
nodes_at_center_grpA <- c(7)
nodes_in_cytoplasam_grpA <- c(3)
nodes_at_edges_grpB <- c(2,8,10)
nodes_at_center_grpB <- c(4)
电流输出
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)