igraph 網路版面配置
igraph 套件提供多種內建的網路視覺化版面配置演算法。根據網路的大小不同,不同的版面配置在呈現結構時的效果也會不同。理想情況下,最佳的版面配置應該能讓網路中彼此相交的邊盡量少。在這個練習中,你會試用其中幾種預設的版面配置演算法。每次重新執行繪圖程式碼,即使是同一種版面配置,結果也會略有不同。重複幾次有助於找到你網路最合適、最清楚的視覺化結果。
本練習屬於課程
R 的 Network Analysis
練習說明
- 在
plot函式中,將layout參數改為layout_in_circle(),繪製圓形網路。 - 在
plot函式中,將layout參數改為layout_with_fr(),使用 Fruchterman-Reingold 版面配置繪製網路。 - 你也可以用每個頂點的(x, y)座標矩陣來指定版面配置。這裡使用
layout_as_tree()產生座標矩陣m,再把m傳給plot()的layout參數來繪圖。 - 要選到合適的版面配置常常不容易。幸好
igraph提供layout_nicely(),會嘗試為給定的圖形物件選出最合適的版面配置函式。請用這個函式產生矩陣m1,並用這些座標來繪製網路。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
library(igraph)
# Plot the graph object g1 in a circle layout
plot(g1, vertex.label.color = "black", layout = ___(g1))
# Plot the graph object g1 in a Fruchterman-Reingold layout
plot(g1, vertex.label.color = "black", layout = ___(g1))
# Plot the graph object g1 in a Tree layout
m <- ___(g1)
plot(g1, vertex.label.color = "black", layout = m)
# Plot the graph object g1 using igraph's chosen layout
___ <- layout_nicely(___)
plot(___, vertex.label.color = "black", layout = ___)