欢迎您访问 最编程 本站为您分享编程语言代码,编程技术文章!
您现在的位置是: 首页

官方 Gephi 手册:关系可视化网络图工具简明教程

最编程 2024-07-07 16:18:57
...

Gephi 和网络图

今天要分享的一款网络图工具:Gephi。

你可能没听过 Gephi,但说起百度的 Echarts和阿里的 Antv Data,一定不陌生。

在这两款的数据可视化产品的解决方案中,描述「对象与对象之间有关联关系或相互作用」的数据表现形式时,分别采用了「关系图」和「一般图」来描述。

Echarts


Echarts

Antv


Antv

看了上面的图你一定对本文要介绍的内容有了基本的轮廓了。

「网络图」是对一类关系型图表的泛称,多用于一些关系型网络的数据分析的场景,例如社交网络分析、生物网络分析。

「网络图」描述的是多个节点之间的相关(互)关系,包含网络中心性、度、中间性和亲密性等指标,其他的还包括密度、路径长度、模块化和聚类系数等。

听球不懂

Don't worry,不要不战而退。

我第一次看到英文介绍的时候脑仁儿也有点炸,但这些指标是网络图的数据分析核心,不得不提,但并非不得不理解。其实如果你有深度应用的需求,就能逐步在实验过程中理解并消化这些看上去生涩的知识点,在此不赘述。

今天我将以一个社交网络分析的实验来贯穿对官网「gephi-tutorial-quick_start」的介(fān)绍(yì)。

先到官网瞅一瞅→ Gephi 官网

官网

这款开源免费的网络图可视化工具最新版本为 0.9.2,可运行于 Windows, Mac OS X and Linux,三平台通杀。点击【Download FREE Gephi0.9.2】下载 Gephi。

官网描述其四大特点:

  • 人人都会:不需要编程技术就可以构建你想要的网络图(然而 Gephi 是支持 code 的????)
  • 颜值担当:专有的渲染引擎,助力高质量的视觉展现
  • 本地支持:支持包含众多本地文件格式,也就是说不需要网络支撑也可以用
  • 高定制化:包括布局、指标、数据源、工具箱和渲染预设等,都可以通过插件实现定制化

听起来就很美,对不对~

Downloading...

下载安装完成开始使用,发现有一份儿《Gephi 快速上手指南》摆在我们面前,不多说打开它。

手册简明的介绍了 Gephi 的基本使用方法,包含:

  • 导入文件(数据)
  • 可视化图表
  • 布局设置
  • 按节点的属性(颜色和尺寸)排列
  • 分区、数据过滤
  • 预览、导出、保存
image

Gephi Tutorial Quick Start

Welcome to this introduction tutorial. It will guide you to the basic steps of network visualization and manipulation in Gephi.
Gephi version 0.7alpha2 was used to do this tutorial.

欢迎使用 Gephi 指南。该指南会告诉你学会在 Gephi 中构建网络可视化、操作的基本步骤。使用版本是 V 0.7alpha2。

Open Graph File

  • Download the file LesMiserables.gexf
  • In the menubar, go to File Menu and Open...


    image

P.S 指南提供了一个文件,我实验中用的是另一个文件)

打开文件。在菜单栏中,找到并打开你的文件可以编辑已有的图。Gephi 支持的文件格式很多...

重要的是支持 Excel 格式! 重要的是支持 Excel 格式! 重要的是支持 Excel 格式!

听到老熟人 Excel,是否突然感觉学习曲线变平缓了很多?????????????

这里选择打开一个 xls 文件,里面包含 nodes 表、 edges 表。

nodes 表里放节点的数据,edges 放关系数据。

nodes 表里数据需要最基本的是 id,edges 表里数据需要最基本的是 source 和 target。

nodes 表,除了必须的 id 外,我还记录了 Label,用于网络图的节点名字显示。

image

edges 表,除了必须的两个字段,我还记录了 id,Weight,type,label,但这些都不是必须的。

image

(p.s 我实测 xlsx 在有多个 sheet 的时候存在问题,没有专研问题,你们可自行测试)

分别导入 sheet1 和 sheet2(对,两次),对应选择导入类型 import as 为 Nodes table 和 Edges table

image

Import Report

When your filed is opened, the report sum up data found and issues.

  • Number of nodes
  • Number of edges
  • Type of graph

Click on OK to validate and see the graph


image

导入报告。当你打开文件后,报告会呈现汇总数据和问题,包含:

  • 节点的数量
  • 边的数量(节点之间关系)
  • 图表类型(有向图 or 无向图)

点击【ok】验证查看图表

You should now see a graph

Nodes position is random at first, so you may see a slighty different representation.


image

你可以看到导入的数据生成的网络图了。节点位置都是随机生成的,所以你可能看到的和想象当中的有点点区别。

Graph Visualization

  • Use your mouse to move and scale the visualization - Zoom: Mouse Wheel - Pan: Right Mouse Drag
  • Locate the “Edge Thickness” slider on the bottom
  • If you loose your graph, reset the position
image

图表可视化。用鼠标滚轮和邮件可以移动、缩放图像,调整 "Edge Thickness" 控制线条的粗细,"reset the position" 可以帮助你将图像缩放到最全视角

Layout the graph

Layout algorithms sets the graph shape, it is the most essential action.

  • Locate the Layout module, on the left panel.
  • Choose“Force Atlas”,You can see the layout properties below, leave default values.
  • Click on 【Run】to launch the algorithm
image

设置图表的布局。系统内预置的布局的算法设定图表的展现,不可或缺。在左侧的 Layout 面板中选择 "Force Atlas",面板会显示对应的属性设置,保持默认设置点击【Run】启动算法。

Control the layout

The purpose of Layout Properties is to let you control the algorithm in order to make a aesthetically pleasing representation.

  • Set the“Repulsion strengh”at 10 000 to expand the graph.
  • Type“Enter”to validate the changed value.
  • And now【Stop】 the algorithm.
image

控制布局。布局算法的属性的目的是为了使网络图有更赏心悦目的展现效果。将 “Repulsion strengh” 的值设置为 10000 以便于让图表更舒展,回车确认修改(后可以看到效果),然后点击【Stop】停止算法。

你现在可以看到调整后的图表的布局样子。

image

Ranking (color)

Ranking module lets you configure node’s color and size.

Locate Ranking module, in the top left.

  • Choose “Degree” as a rank parameter.
  • Click on 【Apply】to see the result.
image

Let's configure colors>

  • Move your mouse over the gradient component
  • Double-click on triangles to configure the color
image

排列(按颜色)。排列模块让你可以配置节点的颜色和大小。你可以在左上侧找到 Appearance 面板找到 Nodes→ Ranking,在下拉框中选择 “Degree” 作为排列的参数,然后点击【Apply】就可以看到结果。

配置颜色。鼠标在滑条上可改变颜色的梯度,双击三角形可以配置颜色。点击右侧
image

可以使用默认的配色方案。

Ranking result table

(我在当 0.9.2 版本中没有此功能,后面问清楚了我在补充到文章中)

Metrics

We will calculate the average path length for the network. It computes the path length for all possibles pairs of nodes and give information about how nodes are close from each other.

  • Locate the Statistics module on the right panel.
  • Click on 【Run】 near “Average Path Length”.
image

Metrics available

image

指标度量。我们将计算所有可能的配对的节点的路径长度的均值作为网络的「平均路径长度」,以便于我们知道节点于节点之间的亲密程度。定位到右侧的 Statistics 模块,找到“Average Path Length”,点击【Run】运行。

运行完成会得到一个报告反馈,告诉及计算的结果,比如这里报告了中间性,集中性等情况。

image

Ranking(Size)

Metrics generates general reports but also results for each node. Thus three new values have been created by the “Average Path Length” algorithm we ran

  • Betweeness Centrality
  • Closeness Centrality
  • Eccentricity

指标度量不只是生成报告同样会影响到每一个节点。我们运行 “Average Path Length” 算法以后,会生成三个新值,分别是 Betweeness Centrality ,Closeness Centrality ,Eccentricity。

  • Go back to Ranking
  • Select“Betweeness Centrality” in the list.
  • This metrics indicates influencial nodes for highest value.
image

返回到排列中。选择 “Betweeness Centrality” 参数。这个指标会直接指明最有影响力的节点。

Ranking(Size)

The node's size will be set now.Colors remain the"Degree"indicator.>

  • Sselect the diamond icon in the toolbar for size
  • Set a min size at 10 and a manx sieze at 50
  • And click on 【Apply】 to see the result.

现在我们来设置节点的尺寸大小。颜色保持使用 “Degree” 的指标。选择工具栏上的尺寸图标,设置尺寸最小为 10 ,最大为 50,然后点击【Apply】查看结果。

image

Layout again

The layout is not completely satisfying,as big nodes can overlap smaller.
The “Force Atlas” algorithm has an option to take node size in account when layouting.

  • Go Back to the Layout panel.
  • Check the “Adjust by Sizes” option and run again the algorithm for short moment.
  • You can see nodes are not overlapping anymore

再次布局。可以看到布局并非完全让你满意,例如一些大的节点就会重叠在较小的节点之上形成覆盖。“Force Atlas”算法则有一些设置项在布局时考虑到节点的尺寸。返回到 Layout 面板,将 “Adjust by Sizes” 勾选后重新运行算法,节点此时不再重叠了。

Show Labels

Let's explore the network more in details now that colors and size indicates central nodes>

  • Dsiplay node labels
  • Set label size proportional to node size
  • Set label size with the scale slider
image

展示标签。现在可以通过颜色和节点大小表明各个中心节点,我们来探究一下更多细节。显示节点的标签名称,设置按节点尺寸匹配标签文本大小,通过滑条直接设置标签尺寸。

Community detection

The ability to detect and study communities is central in network analysis.We would like to colorize clusters in our example.
Gephi implements the Louvain method,available form the Statistics panel.
Click on Run near the "Modularity" line

  • Select "Randomize" on the panel
  • Click on OK to lancuh the detection

社区群侦测。甄别和研究社区社群的能力是网络分析的核心。这个例子中,我们将依赖 Gephi 在 Statistics 面板中提供的方法,分集群对节点着色。点击 run 运行 Statistics 面板中的“Modularity”。对话框中选择 "Randomize" 随机分布,点击 ok 运行侦测。

Partition

The community detection algorithm created a "Modularity Class" value for each node.
The partition module can use this new data to colorize communities

  • Locate the Partition module on the left panel.
  • Immediately click on the "Refresh" button to populate the partition list.
  • Select "Modularity Class" in the partition list.
  • you can see that 9 communities were found,could be different for you.A random color has been set for each community indetifier
  • Click to Apply to colorize nodes.
image

分区。“社群侦测算法”为每一个节点创建了 “Modularity Class”。节点的分区 Partition 模块里可以用这个新的参数给给不同的社群标注不同的颜色(以便于区分出社区群体)。在左侧的 Apprearance 面板中,找到节点分区模块,点击【Refresh】按钮去构建分区列表。选择“Mdoularity Class” 后,节点被分为了 9 个不同的社群,每个社群有自己的颜色以便于区分。点击 Apply 给渲染节点颜色。

最终效果还是比较让人满意的。因为涉及到个人信息,这里我没有设置显示节点的名称。

image

Preview

  • Before exporting you graph as a SVG or PDF file,go to Preview to:
    • See exactly how the graph will look like
    • Put the last touch
  • Select the "Preview" tab in the banner:
  • Click on Refresh to see the preview
  • Preview Settings sipports Presets,click on the presets list and try different configuration

预览。导出 SVG 或 PDF 之前,先预览一下。这样可以直观的看到图像的外观然后做一些最后处理。选择 “Preview” 选项卡,点击 Refresh 查看预览。有一些预设的预览设定可以选择,尝试不同的风格。

image

(这里我隐藏了 Label)

最后导出为 SVG/PDF/PNG 就随你心情了。

Conclusion

In this tutorial you learned the baisc process to open,visualize,manipulate and render a network file with Gephi
Go furhter:https://gephi.org/users/

image

这份指南让你学习如何用 Gephi 打开文件、可视化、操作和渲染网络,若想深入学习,可以参照官方文档:https://gephi.org/users/