如何在 R 中可视化大型网络? [英] How to visualize a large network in R?

查看:25
本文介绍了如何在 R 中可视化大型网络?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

网络可视化在实践中在科学中变得普遍.但随着网络规模的扩大,常见的可视化变得越来越没用.节点/顶点和链接/边实在是太多了.通常,可视化工作最终会产生毛球".

已经提出了一些新方法来克服这个问题,例如:

  • 边缘捆绑:
    • .但是,我在这里搜索的不是一般的软件推荐,而是具体示例(使用上面提供的数据),这些技术有助于通过使用 R 对大型网络进行良好的可视化(与这个线程:R:点太多的散点图).

      解决方案

      另一种可视化超大型网络的方法是使用 BioFabric (www.BioFabric.org),它使用水平线而不是指向代表节点.然后使用垂直线段显示边缘.此技术的快速 D3 演示显示在:http://www.biofabric.org/画廊/页面/SuperQuickBioFabric.html.

      BioFabric 是一个 Java 应用程序,但一个简单的 R 版本可从以下网址获得:https://github.com/wjrl/RBioFabric.

      这是一段R代码:

       # 你需要'devtools':install.packages("devtools")图书馆(开发工具)# 你需要 igraph:install.packages("igraph")图书馆(igraph)# 从 GitHub 安装并加载RBioFabric"install_github('RBioFabric', username='wjrl')图书馆(RBioFabric)## 这是问题中提供的示例:#set.seed(123)bfGraph = barabasi.game(1000)# 这个例子有 1000 个节点,就像提供的例子一样,但它# 在每一步添加 6 条边,形成一个有趣的形状;玩# 使用不同的值.# bfGraph = barabasi.game(1000, m=6,directed=FALSE)# 画出来!为获得最佳效果,请将 PDF 设为相同# 纵横比作为网络,虽然有点额外的高度# 覆盖顶部标签.鉴于网络的规模,# 宽度为 100 的 PDF 为我们提供了良好的分辨率.高度 <- vcount(bfGraph)宽度 <- ecount(bfGraph)纵横比<-高度/宽度;绘图宽度 <- 100.0plotHeight <- 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 是我编写的工具.

      Network visualizations become common in science in practice. But as networks are increasing in size, common visualizations become less useful. There are simply too many nodes/vertices and links/edges. Often visualization efforts end up in producing "hairballs".

      Some new approaches have been proposed to overcome this issue, e.g.:

      I am sure that there are many more approaches. Thus, my question is: How to overcome the hairball issue, i.e. how to visualize large networks by using R?

      Here is some code that simulates an exemplary network:

      # 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
      

      This questions is related to Visualizing Undirected Graph That's Too Large for GraphViz?. However, here I am searching not for general software recommendations but for concrete examples (using the data provided above) which techniques help to make a good visualization of a large network by using R (comparable to the examples in this thread: R: Scatterplot with too many points).

      解决方案

      Another way to visualize very large networks is with BioFabric (www.BioFabric.org), which uses horizontal lines instead of points to represent the nodes. Edges are then shown using vertical line segments. A quick D3 demo of this technique is shown at: http://www.biofabric.org/gallery/pages/SuperQuickBioFabric.html.

      BioFabric is a Java application, but a simple R version is available at: https://github.com/wjrl/RBioFabric.

      Here is a snippet of R code:

       # 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()
      

      Here is a shot of the BioFabric version of the data provided by the questioner, though networks created with values of m > 1 are more interesting. The inset detail shows a close-up of the upper left corner of the network; node BF4 is the highest-degree node in the network, and the default layout is a breadth-first search of the network (ignoring edge directions) starting from that node, with neighboring nodes traversed in order of decreasing node degree. Note that we can immediately see that, for example, about 60% of node BF4's neighbors are degree 1. We can also see from the strict 45-degree lower edge that this 1000-node network has 999 edges, and is therefore a tree.

      Full disclosure: BioFabric is a tool that I wrote.

      这篇关于如何在 R 中可视化大型网络?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆