为节点着色
在本练习中,您将根据流失状态为网络中的节点着色。已流失的客户标为红色,未流失的客户标为白色。 然后,您将再次可视化该网络。
本练习是课程的一部分
使用 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)