ComenzarEmpieza gratis

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 ejercicio forma parte del curso

Predictive Analytics using Networked Data in R

Ver curso

Instrucciones del ejercicio

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

Ejercicio interactivo práctico

Prueba este ejercicio y completa el código de muestra.

# 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 y ejecutar código