노드에 색 입히기
이번 연습에서는 이탈(churn) 상태에 따라 네트워크의 노드에 색을 지정해 보겠습니다. 이탈한 고객은 빨간색, 이탈하지 않은 고객은 흰색으로 표시해요. 그리고 네트워크를 다시 시각화합니다.
이 연습은 강의의 일부입니다
R로 배우는 네트워크 데이터 기반 Predictive Analytics
연습 안내
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)