网络可视化在科学实践中变得很常见。但随着网络规模的不断扩大,常见的可视化变得不再那么有用。节点/顶点和链接/边太多了。通常,可视化工作最终会产生“毛团”。
已经提出了一些新方法来解决这个问题,例如:
- 边缘捆绑:
- 分层边缘捆绑:
- 组属性布局:
我确信还有更多的方法。因此,我的问题是: 如何克服毛球问题,即如何使用 R 可视化大型网络?
下面是一些模拟示例网络的代码:
# Load packages
lapply(c("devtools", "sna", "intergraph", "igraph", "network"), install.packages)
library(devtools)
devtools::install_github(repo="ggally", username="ggobi")
lapply(c("sna", "intergraph", "GGally", "igraph", "network"),
require, character.only=T)
# Set up data
set.seed(123)
g <- barabasi.game(1000)
# Plot data
g.plot <- ggnet(g, mode = "fruchtermanreingold")
g.plot
此问题涉及 Visualizing Undirected Graph That's Too Large for GraphViz? 。然而,我在这里搜索的不是一般软件建议,而是具体示例(使用上面提供的数据),这些技术有助于使用 R 实现大型网络的良好可视化(与中的示例相比)此线程: R: Scatterplot with too many points )。
最佳答案
可视化大型网络的另一种方法是使用 BioFabric (www.BioFabric.org),它使用水平线而不是点来表示节点。然后使用垂直线段显示边缘。此技术的快速 D3 演示如下:http://www.biofabric.org/gallery/pages/SuperQuickBioFabric.html .
BioFabric 是一个 Java 应用程序,但可以在以下位置找到简单的 R 版本:https://github.com/wjrl/RBioFabric .
这是 R 代码片段:
# You need 'devtools':
install.packages("devtools")
library(devtools)
# you need igraph:
install.packages("igraph")
library(igraph)
# install and load 'RBioFabric' from GitHub
install_github('RBioFabric', username='wjrl')
library(RBioFabric)
#
# This is the example provided in the question:
#
set.seed(123)
bfGraph = barabasi.game(1000)
# This example has 1000 nodes, just like the provided example, but it
# adds 6 edges in each step, making for an interesting shape; play
# around with different values.
# bfGraph = barabasi.game(1000, m=6, directed=FALSE)
# Plot it up! For best results, make the PDF in the same
# aspect ratio as the network, though a little extra height
# covers the top labels. Given the size of the network,
# a PDF width of 100 gives us good resolution.
height <- vcount(bfGraph)
width <- ecount(bfGraph)
aspect <- height / width;
plotWidth <- 100.0
plotHeight <- plotWidth * (aspect * 1.2)
pdf("myBioFabricOutput.pdf", width=plotWidth, height=plotHeight)
bioFabric(bfGraph)
dev.off()
这是提问者提供的 BioFabric 版本数据的截图,尽管使用 m > 1 的值创建的网络更有趣。插图细节显示了网络左上角的特写;节点 BF4 是网络中度数最高的节点,默认布局是从该节点开始对网络进行广度优先搜索(忽略边缘方向),按照节点度数递减的顺序遍历相邻节点。请注意,我们可以立即看到,例如,大约 60% 的节点 BF4 的邻居的度数为 1。我们还可以从严格的 45 度下边看到,这个 1000 个节点的网络有 999 个边,因此是一棵树。
全面披露:BioFabric 是我编写的一个工具。
关于r - 如何在 R 中可视化大型网络?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22453273/