開始使用免費開始

建立 igraph 物件

在這裡你會學到如何從邊列表(edgelist)中的資料建立一個 igraph 物件。這份資料記錄了一組學生之間的友誼。你也會學到如何製作最基本的網路視覺化。

friends 資料框中的每一列代表網路中的一條邊。

本練習屬於課程

R 的 Network Analysis

檢視課程

練習說明

  • 使用 head() 檢視資料框 friends 的前幾列。
  • 使用 as.matrix() 從資料框 friends 建立新的物件 friends.mat
  • 使用 graph.edgelist() 將變數轉為 igraph 物件 g
  • 使用 plot() 繪製此網路的基本圖形。

動手互動練習

試著完成這個範例程式碼,體驗一下這個練習。

# Load igraph
library(igraph)

# Inspect the first few rows of the dataframe 'friends'
___(friends)

# Convert friends dataframe to a matrix
friends.mat <- ___(friends)

# Convert friends matrix to an igraph object
g <- graph.edgelist(___, directed = FALSE)


# Make a very basic plot of the network
___(g)

編輯並執行程式碼