CommencerCommencer gratuitement

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.

Cet exercice fait partie du cours

Predictive Analytics using Networked Data in R

Afficher le cours

Instructions

  • 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.

Exercice interactif pratique

Essayez cet exercice en complétant cet exemple de code.

# 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)
Modifier et exécuter le code