LoslegenKostenlos loslegen

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.

Diese Übung ist Teil des Kurses

Predictive Analytics using Networked Data in R

Kurs anzeigen

Anleitung zur Übung

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

Interaktive Übung

Versuche dich an dieser Übung, indem du diesen Beispielcode vervollständigst.

# 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)
Code bearbeiten und ausführen