Используйте словарь поиска цветов и назначьте его цвету вершины.

аюсь изменить цвет узлов в зависимости от месяца. На данный момент я сделал это таким образом, который не является лаконичным и не будет работать для больших наборов данных. Есть ли лучший способ сделать это?

Data <- read.csv(.....) 

library(igraph)   

MartixData <- as.matrix(Data)

NetworkData <- graph.adjacency(MatrixData, mode="directed", weighted=TRUE)

V(NetworkData)

V(NetworkData)$month <- c("June", "July", "July", "February", "September", "June", "September", "June", "December", "September", "March", "April", "September")

plot(NetworkData, layout=layout.circle, vertex.color=c("yellow", "red", "red", "blue", "pink","yellow", "pink", "yellow", "gray", "pink", "black", "orange", "pink"))

Любая помощь приветствуется!

#Results for dput(NetworkData)
structure(list(13, TRUE, 
  c(0, 1, 1, 2, 5, 6, 7, 7, 8, 9, 10, 10, 12, 12, 12, 12, 12), 
  c(11, 4, 12, 0, 12, 1, 6, 12, 1, 4, 9, 12, 1, 5, 7, 10, 11), 
  c(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16), 
  c(3, 5, 8, 12, 1, 9, 13, 6, 14, 10, 15, 0, 16, 2, 4, 7, 11), 
  c(0, 1, 3, 4, 4, 4, 5, 6, 8, 9, 10, 12, 12, 17), 
  c(0, 1, 4, 4, 4, 6, 7, 8, 9, 9, 10, 11, 13, 17), 
  list(c(1, 0, 1), structure(list(), .Names = character(0)), 
 structure(list(name = c("A", "B", "C", "D", "E", "F", 
    "G", "H", "I", "J", "K", "L", "M"), month = c("June", 
    "July", "July", "February", "September", "June", "September", 
    "June", "December", "September", "March", "April", "September"
    )), .Names = c("name", "month")), structure(list(weight = c(6, 
    6, 7, 6, 7, 6, 6, 7, 7, 7, 6, 7, 7, 7, 7, 7, 7)), .Names = "weight"))), class = "igraph")

Ответы на вопрос(1)

Решение Вопроса

Используйте словарь поиска цветов и назначьте его цвету вершины.

myCols <- setNames(c("yellow", "red", "blue", "pink", "gray", "black", "orange"),
                   c("June", "July", "February", "September", "December", "March", "April"))

# assign a colour for vertex
V(NetworkData)$color <- myCols[V(NetworkData)$month]

# then plot, no need to use "vertex.color="
plot(NetworkData, layout = layout.circle)

Ваш ответ на вопрос