視覺化最大幫團
在網路視覺化中,你常常需要擷取網路的一部分,來檢視特定頂點之間的連結。在這裡,你要為《阿甘正傳》網路中的最大幫團建立視覺化。在上一個練習中,你已經找出有 2 個大小為 9 的幫團。你會先從主網路中擷取出這兩個幫團來建立 2 個新的 igraph 物件,然後把它們並排繪製。函式 subgraph() 可以讓你選擇要在新的網路物件中保留哪些頂點。
本練習屬於課程
R 的 Network Analysis
練習說明
- 將網路中最大幫團的清單指定給物件
lc。 - 使用函式
subgraph()建立 2 個新的無向子圖。第一個gs1只包含第一個最大幫團的頂點。第二個gs2只包含第二個最大幫團的頂點。為了確保子圖也是無向圖,將此函式包在as.undirected()中。 - 使用
plot()將兩個最大幫團並排視覺化。先執行:par(mfrow=c(1,2)),以確保兩個視覺化結果並排顯示。請將版面配置設為layout.circle(),讓圖形更容易閱讀。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
library(igraph)
# Assign largest cliques output to object 'lc'
lc <- ___(g)
# Create two new undirected subgraphs, each containing only the vertices of each largest clique.
gs1 <- as.undirected(___(g, ___[[1]]))
gs2 <- as.undirected(___(g, ___[[2]]))
# Plot the two largest cliques side-by-side
par(mfrow=c(1,2)) # To plot two plots side-by-side
___(gs1,
vertex.label.color = "black",
vertex.label.cex = 0.9,
vertex.size = 0,
edge.color = 'gray28',
main = "Largest Clique 1",
layout = ___(gs1)
)
___(gs2,
vertex.label.color = "black",
vertex.label.cex = 0.9,
vertex.size = 0,
edge.color = 'gray28',
main = "Largest Clique 2",
layout = ___(gs2)
)