開始使用免費開始

重疊的邊

社群網路的兩個基本組成要素是節點與邊。權重通常為正值。

資料集 edges 包含一個小型網路的邊。兩個節點之間若有多條邊,可能代表這兩個節點的連結比只有一條邊時更強。與其分別顯示每一條邊,你可以讓邊重疊,並將 width 設為邊的數量。

igraph 函式庫與資料集 edges 已載入你的工作環境。

本練習屬於課程

R 的詐欺偵測

檢視課程

練習說明

  • 使用 graph_from_data_frame() 根據資料集 edges 建立一個名為 net 的「無向」圖,並將 directed 設為正確的布林值(TRUEFALSE)。
  • 使用 plot() 繪製網路 net,並將 layout 設為 layout_in_circle(不要加引號 ""!)。
  • 若要得到重疊的邊,對 net 使用 count.multiple(),將結果指定給 E(net)$width。為了「避免」曲線邊,將 E(net)$curved 設為正確的布林值(TRUEFALSE)。
  • 再次以圓形配置繪製 net

動手互動練習

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

# Create a network from the data frame
net <- ___(___, directed = ___)

# Plot the network with the multiple edges
___(___, layout = ___)

# Specify new edge attributes width and curved
E(net)$___ <- ___
E(net)$___ <- ___

# Check the new edge attributes and plot the network with overlapping edges
edge_attr(net)
___(___, layout = ___)
編輯並執行程式碼