始める無料で始める

ノードに色を付ける

この演習では、解約ステータスに応じてネットワーク内のノードに色を付けます。解約した顧客は赤、解約していない顧客は白で表示します。 その後、ネットワークを再度可視化します。

この演習はコースの一部です

R で学ぶネットワークデータの予測分析

コースを見る

演習の手順

  • V(network)$churn と同じ内容のノード属性 color を追加します。
  • 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)
コードを編集して実行