ComeçarComece de graça

Coloring nodes

In this exercise, you will color the nodes in the network depending on the churn status. The customers who have churned will be colored red and the non-churners will be colored white. Then you will visualize the network again.

Este exercício faz parte do curso

Predictive Analytics using Networked Data in R

Ver curso

Instruções do exercício

  • Add a node attribute called color that is the same as V(network)$churn.
  • In V(network)$color, use the gsub() function to replace the string "1" with the string "red".
  • In V(network)$color, use the gsub() function to replace the string "0" with the string "white".
  • Visualize the network again using the plot() function.

Exercício interativo prático

Experimente este exercício completando este código de exemplo.

# 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)
Editar e executar o código