我正在使用 R 中的 igraph 创建一个由大约 600 个节点包围的单个“中心”节点的网络可视化。
节点重叠,然后我可以使用这个问题的答案(使用 qgraph)来解决。
但是,此解决方案似乎仅适用于大小相同的节点。在我的网络中,节点大小是可变的。有没有办法通过在确定节点之间的距离时考虑节点大小来避免重叠?
下面的示例代码:
# create network
net <- graph_from_data_frame(d=links, vertices=nodes, directed=T)
# set colors
colrs <- c("#8DD3C7", "#FFFFB3")
V(net)$color <- colrs[V(net)$type]
# no labels
V(net)$label <- NA
# create a network graph with non-overlapping nodes:
# using https://stackoverflow.com/questions/39290909/igraph-resolving-tight-overlapping-nodes
e <- get.edgelist(net,names = F)
l <- qgraph.layout.fruchtermanreingold(e,vcount=vcount(net))
plot(net,layout=l,vertex.size=4,edge.arrow.mode=0,vertex.label=NA)
这是结果:
但是现在当我更改节点大小时:
# setting node size based on data
V(net)$size <- V(net)$nodesize;
# plot result
plot(net,layout=l,edge.arrow.mode=0,vertex.label=NA)
...节点重叠:
感谢您在这里的任何帮助!
* 编辑 - 添加示例数据集:前 50 个节点 *
节点数据:
dput(head(nodes,50))
structure(list(id = c("s01", "s02", "s03", "s04", "s05", "s06", "s07", "s08",
"s09", "s10", "s11", "s12", "s13", "s14", "s15", "s16", "s17", "s18", "s19",
"s20", "s21", "s22", "s23", "s24", "s25", "s26", "s27", "s28", "s29", "s30",
"s31", "s32", "s33", "s34", "s35", "s36", "s37", "s38", "s39", "s40", "s41",
"s42", "s43", "s44", "s45", "s46", "s47", "s48", "s49", "s50"), nodesize =
c(50, 2.025, 2.025, 3.5, 1, 0.725, 2.875, 1.6, 0.175, 2.175, 0, 0.675, 0.5,
15.7, 1.4, 0.4, 1.375, 0.425, 0.55, 7, 10.375, 1.125, 0.325, 0.925, 3.6, 0.525,
0.9, 0.1, 0.5, 2.3, 1.825, 1.95, 0.325, 0.9, 3, 0.475, 0.1, 2.975, 6.1, 9.225,
0.65, 3.05, 2.925, 6.35, 0.7, 0.2, 0.6, 1.7, 1.675, 1.425), type = c(1L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L)), row.names = c(NA, 50L), class =
"data.frame")
链接数据:
dput(head(links,49))
structure(list(from = c("s01", "s01", "s01", "s01", "s01", "s01",
"s01", "s01", "s01", "s01", "s01", "s01", "s01", "s01", "s01",
"s01", "s01", "s01", "s01", "s01", "s01", "s01", "s01", "s01",
"s01", "s01", "s01", "s01", "s01", "s01", "s01", "s01", "s01",
"s01", "s01", "s01", "s01", "s01", "s01", "s01", "s01", "s01",
"s01", "s01", "s01", "s01", "s01", "s01", "s01"), to = c("s02",
"s03", "s04", "s05", "s06", "s07", "s08", "s09", "s10", "s11",
"s12", "s13", "s14", "s15", "s16", "s17", "s18", "s19", "s20",
"s21", "s22", "s23", "s24", "s25", "s26", "s27", "s28", "s29",
"s30", "s31", "s32", "s33", "s34", "s35", "s36", "s37", "s38",
"s39", "s40", "s41", "s42", "s43", "s44", "s45", "s46", "s47",
"s48", "s49", "s50")), row.names = c(NA, 49L), class = "data.frame")