Gephi 和網(wǎng)絡(luò)圖
今天要分享的一款網(wǎng)絡(luò)圖工具:Gephi。
你可能沒聽過 Gephi匠璧,但說起百度的 Echarts和阿里的 Antv Data豁辉,一定不陌生把将。
在這兩款的數(shù)據(jù)可視化產(chǎn)品的解決方案中,描述「對象與對象之間有關(guān)聯(lián)關(guān)系或相互作用」的數(shù)據(jù)表現(xiàn)形式時(shí)王财,分別采用了「關(guān)系圖」和「一般圖」來描述卵迂。
Echarts
Antv
看了上面的圖你一定對本文要介紹的內(nèi)容有了基本的輪廓了。
「網(wǎng)絡(luò)圖」是對一類關(guān)系型圖表的泛稱绒净,多用于一些關(guān)系型網(wǎng)絡(luò)的數(shù)據(jù)分析的場景见咒,例如社交網(wǎng)絡(luò)分析、生物網(wǎng)絡(luò)分析挂疆。
「網(wǎng)絡(luò)圖」描述的是多個節(jié)點(diǎn)之間的相關(guān)(互)關(guān)系改览,包含網(wǎng)絡(luò)中心性、度缤言、中間性和親密性等指標(biāo)宝当,其他的還包括密度、路徑長度胆萧、模塊化和聚類系數(shù)等庆揩。
Don't worry,不要不戰(zhàn)而退。
我第一次看到英文介紹的時(shí)候腦仁兒也有點(diǎn)炸盾鳞,但這些指標(biāo)是網(wǎng)絡(luò)圖的數(shù)據(jù)分析核心犬性,不得不提,但并非不得不理解腾仅。其實(shí)如果你有深度應(yīng)用的需求,就能逐步在實(shí)驗(yàn)過程中理解并消化這些看上去生澀的知識點(diǎn)套利,在此不贅述推励。
今天我將以一個社交網(wǎng)絡(luò)分析的實(shí)驗(yàn)來貫穿對官網(wǎng)「gephi-tutorial-quick_start」的介(fān)紹(yì)。
先到官網(wǎng)瞅一瞅→ Gephi 官網(wǎng)
這款開源免費(fèi)的網(wǎng)絡(luò)圖可視化工具最新版本為 0.9.2肉迫,可運(yùn)行于 Windows, Mac OS X and Linux验辞,三平臺通殺。點(diǎn)擊【Download FREE Gephi0.9.2】下載 Gephi喊衫。
官網(wǎng)描述其四大特點(diǎn):
- 人人都會:不需要編程技術(shù)就可以構(gòu)建你想要的網(wǎng)絡(luò)圖(然而 Gephi 是支持 code 的??)
- 顏值擔(dān)當(dāng):專有的渲染引擎跌造,助力高質(zhì)量的視覺展現(xiàn)
- 本地支持:支持包含眾多本地文件格式,也就是說不需要網(wǎng)絡(luò)支撐也可以用
- 高定制化:包括布局族购、指標(biāo)壳贪、數(shù)據(jù)源、工具箱和渲染預(yù)設(shè)等寝杖,都可以通過插件實(shí)現(xiàn)定制化
聽起來就很美违施,對不對~
Downloading...
下載安裝完成開始使用,發(fā)現(xiàn)有一份兒《Gephi 快速上手指南》擺在我們面前瑟幕,不多說打開它磕蒲。
手冊簡明的介紹了 Gephi 的基本使用方法,包含:
- 導(dǎo)入文件(數(shù)據(jù))
- 可視化圖表
- 布局設(shè)置
- 按節(jié)點(diǎn)的屬性(顏色和尺寸)排列
- 分區(qū)只盹、數(shù)據(jù)過濾
- 預(yù)覽辣往、導(dǎo)出、保存
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 指南殖卑。該指南會告訴你學(xué)會在 Gephi 中構(gòu)建網(wǎng)絡(luò)可視化站削、操作的基本步驟。使用版本是 V 0.7alpha2懦鼠。
Open Graph File
- Download the file LesMiserables.gexf
In the menubar, go to File Menu and Open...
image
(P.S 指南提供了一個文件钻哩,我實(shí)驗(yàn)中用的是另一個文件)
打開文件。在菜單欄中肛冶,找到并打開你的文件可以編輯已有的圖街氢。Gephi 支持的文件格式很多...
重要的是支持 Excel 格式! 重要的是支持 Excel 格式睦袖! 重要的是支持 Excel 格式珊肃!
聽到老熟人 Excel,是否突然感覺學(xué)習(xí)曲線變平緩了很多???????
這里選擇打開一個 xls 文件伦乔,里面包含 nodes 表厉亏、 edges 表。
nodes 表里放節(jié)點(diǎn)的數(shù)據(jù)烈和,edges 放關(guān)系數(shù)據(jù)爱只。
nodes 表里數(shù)據(jù)需要最基本的是 id,edges 表里數(shù)據(jù)需要最基本的是 source 和 target招刹。
nodes 表恬试,除了必須的 id 外,我還記錄了 Label疯暑,用于網(wǎng)絡(luò)圖的節(jié)點(diǎn)名字顯示训柴。
edges 表,除了必須的兩個字段妇拯,我還記錄了 id,Weight,type,label幻馁,但這些都不是必須的。
(p.s 我實(shí)測 xlsx 在有多個 sheet 的時(shí)候存在問題越锈,沒有專研問題仗嗦,你們可自行測試)
分別導(dǎo)入 sheet1 和 sheet2(對,兩次)瞪浸,對應(yīng)選擇導(dǎo)入類型 import as 為 Nodes table 和 Edges table
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
導(dǎo)入報(bào)告儒将。當(dāng)你打開文件后,報(bào)告會呈現(xiàn)匯總數(shù)據(jù)和問題对蒲,包含:
- 節(jié)點(diǎn)的數(shù)量
- 邊的數(shù)量(節(jié)點(diǎn)之間關(guān)系)
- 圖表類型(有向圖 or 無向圖)
點(diǎn)擊【ok】驗(yàn)證查看圖表
You should now see a graph
Nodes position is random at first, so you may see a slighty different representation.
image
你可以看到導(dǎo)入的數(shù)據(jù)生成的網(wǎng)絡(luò)圖了钩蚊。節(jié)點(diǎn)位置都是隨機(jī)生成的,所以你可能看到的和想象當(dāng)中的有點(diǎn)點(diǎn)區(qū)別蹈矮。
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
圖表可視化砰逻。用鼠標(biāo)滾輪和郵件可以移動、縮放圖像泛鸟,調(diào)整 "Edge Thickness" 控制線條的粗細(xì)蝠咆,"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
設(shè)置圖表的布局。系統(tǒng)內(nèi)預(yù)置的布局的算法設(shè)定圖表的展現(xiàn)北滥,不可或缺刚操。在左側(cè)的 Layout 面板中選擇 "Force Atlas",面板會顯示對應(yīng)的屬性設(shè)置再芋,保持默認(rèn)設(shè)置點(diǎn)擊【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
控制布局。布局算法的屬性的目的是為了使網(wǎng)絡(luò)圖有更賞心悅目的展現(xiàn)效果济赎。將 “Repulsion strengh” 的值設(shè)置為 10000 以便于讓圖表更舒展鉴逞,回車確認(rèn)修改(后可以看到效果)记某,然后點(diǎn)擊【Stop】停止算法。
你現(xiàn)在可以看到調(diào)整后的圖表的布局樣子构捡。
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.
imageLet's configure colors>
- Move your mouse over the gradient component
- Double-click on triangles to configure the color
image
排列(按顏色)液南。排列模塊讓你可以配置節(jié)點(diǎn)的顏色和大小。你可以在左上側(cè)找到 Appearance 面板找到 Nodes→ Ranking勾徽,在下拉框中選擇 “Degree” 作為排列的參數(shù)滑凉,然后點(diǎn)擊【Apply】就可以看到結(jié)果。
配置顏色捂蕴。鼠標(biāo)在滑條上可改變顏色的梯度譬涡,雙擊三角形可以配置顏色。點(diǎn)擊右側(cè)可以使用默認(rèn)的配色方案啥辨。
Ranking result table
(我在當(dāng) 0.9.2 版本中沒有此功能,后面問清楚了我在補(bǔ)充到文章中)
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”.
imageMetrics available
image
指標(biāo)度量盯腌。我們將計(jì)算所有可能的配對的節(jié)點(diǎn)的路徑長度的均值作為網(wǎng)絡(luò)的「平均路徑長度」溉知,以便于我們知道節(jié)點(diǎn)于節(jié)點(diǎn)之間的親密程度。定位到右側(cè)的 Statistics 模塊腕够,找到“Average Path Length”级乍,點(diǎn)擊【Run】運(yùn)行。
運(yùn)行完成會得到一個報(bào)告反饋帚湘,告訴及計(jì)算的結(jié)果玫荣,比如這里報(bào)告了中間性,集中性等情況大诸。
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
指標(biāo)度量不只是生成報(bào)告同樣會影響到每一個節(jié)點(diǎn)捅厂。我們運(yùn)行 “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” 參數(shù)贿堰。這個指標(biāo)會直接指明最有影響力的節(jié)點(diǎn)辙芍。
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.
現(xiàn)在我們來設(shè)置節(jié)點(diǎn)的尺寸大小。顏色保持使用 “Degree” 的指標(biāo)羹与。選擇工具欄上的尺寸圖標(biāo)故硅,設(shè)置尺寸最小為 10 ,最大為 50纵搁,然后點(diǎn)擊【Apply】查看結(jié)果吃衅。
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
再次布局」羁剩可以看到布局并非完全讓你滿意捐晶,例如一些大的節(jié)點(diǎn)就會重疊在較小的節(jié)點(diǎn)之上形成覆蓋菲语。“Force Atlas”算法則有一些設(shè)置項(xiàng)在布局時(shí)考慮到節(jié)點(diǎn)的尺寸惑灵。返回到 Layout 面板山上,將 “Adjust by Sizes” 勾選后重新運(yùn)行算法,節(jié)點(diǎn)此時(shí)不再重疊了英支。
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
展示標(biāo)簽∨搴叮現(xiàn)在可以通過顏色和節(jié)點(diǎn)大小表明各個中心節(jié)點(diǎn),我們來探究一下更多細(xì)節(jié)干花。顯示節(jié)點(diǎn)的標(biāo)簽名稱妄帘,設(shè)置按節(jié)點(diǎn)尺寸匹配標(biāo)簽文本大小,通過滑條直接設(shè)置標(biāo)簽尺寸池凄。
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
社區(qū)群偵測抡驼。甄別和研究社區(qū)社群的能力是網(wǎng)絡(luò)分析的核心。這個例子中肿仑,我們將依賴 Gephi 在 Statistics 面板中提供的方法致盟,分集群對節(jié)點(diǎn)著色。點(diǎn)擊 run 運(yùn)行 Statistics 面板中的“Modularity”尤慰。對話框中選擇 "Randomize" 隨機(jī)分布馏锡,點(diǎn)擊 ok 運(yùn)行偵測。
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
分區(qū)伟端”溃“社群偵測算法”為每一個節(jié)點(diǎn)創(chuàng)建了 “Modularity Class”。節(jié)點(diǎn)的分區(qū) Partition 模塊里可以用這個新的參數(shù)給給不同的社群標(biāo)注不同的顏色(以便于區(qū)分出社區(qū)群體)责蝠。在左側(cè)的 Apprearance 面板中党巾,找到節(jié)點(diǎn)分區(qū)模塊,點(diǎn)擊【Refresh】按鈕去構(gòu)建分區(qū)列表玛歌。選擇“Mdoularity Class” 后昧港,節(jié)點(diǎn)被分為了 9 個不同的社群,每個社群有自己的顏色以便于區(qū)分支子。點(diǎn)擊 Apply 給渲染節(jié)點(diǎn)顏色创肥。
最終效果還是比較讓人滿意的。因?yàn)樯婕暗絺€人信息值朋,這里我沒有設(shè)置顯示節(jié)點(diǎn)的名稱叹侄。
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
預(yù)覽。導(dǎo)出 SVG 或 PDF 之前昨登,先預(yù)覽一下趾代。這樣可以直觀的看到圖像的外觀然后做一些最后處理。選擇 “Preview” 選項(xiàng)卡丰辣,點(diǎn)擊 Refresh 查看預(yù)覽撒强。有一些預(yù)設(shè)的預(yù)覽設(shè)定可以選擇禽捆,嘗試不同的風(fēng)格。
(這里我隱藏了 Label)
最后導(dǎo)出為 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/
這份指南讓你學(xué)習(xí)如何用 Gephi 打開文件胚想、可視化、操作和渲染網(wǎng)絡(luò)芽隆,若想深入學(xué)習(xí)浊服,可以參照官方文檔:https://gephi.org/users/。