開始使用免費開始

為節點上色

在這個練習中,你要根據是否退訂(churn)來為網路中的節點上色。已退訂的顧客標成紅色,未退訂的顧客標成白色。 接著再將網路視覺化一次。

本練習屬於課程

使用 R 進行網路化資料的預測分析

檢視課程

練習說明

  • 新增名為 color 的節點屬性,內容與 V(network)$churn 相同。
  • V(network)$color 中,使用 gsub() 將字串 "1" 取代為字串 "red"
  • V(network)$color 中,使用 gsub() 將字串 "0" 取代為字串 "white"
  • 使用 plot() 函式再次將網路視覺化。

動手互動練習

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

# Add a node attribute called color
V(network)$___ <- V(network)$churn

# Change the color of churners to red and non-churners to white
V(network)$color <- gsub(___, "red", V(network)$color) 
V(network)$color <- gsub(___, "white", V(network)$color)

# Plot the network
___(___, vertex.label = NA, edge.label = NA,
    edge.color = "black", vertex.size = 2)
編輯並執行程式碼