為節點上色
在這個練習中,你要根據是否退訂(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)