I'm trying to color the vertices according to the dummy variable [color_thresh]. Data looks like the following:
I have tried several suggested methods, but the closest (and simplest) I can do produces the following:
Here is my code for reproducing data and the graph above:
library(igraph)
library(data.tree)
Level_0 = c("TAC_310B_124","TAC_310B_124","TAC_310B_124","TAC_310B_124","TAC_310B_124","TAC_310B_124","TAC_310B_124","TAC_310B_124","TAC_310B_124")
Level_1 = c("","SC_776E_86","SS_A66D_9","SC_776E_86","SC_776E_86","SC_776E_86","SC_776E_86","SC_776E_86","SC_776E_86")
Level_2 = c("","","","TGW_1DD0_42","TGW_1DD0_42","TGW_1DD0_42","TGW_1DD0_42","TGW_1DD0_42","TGW_1DD0_42")
Level_3 = c("","","","","CORB_F2E4_17","CORB_F2E4_22","CORB_AE16_10921","CORB_AE16_10921","CORB_AE16_10921")
Level_4 = c("","","","","","","","CORB_D81E_45","CORB_D81E_45")
Level_5 = c("","","","","","","","","SC_B949_3156")
color_thresh = c(1,0,0,0,0,0,1,0,1)
dataset <- data.frame(Level_0,Level_1,Level_2,Level_3,Level_4,Level_5,color_thresh)
dataset$pathString <- paste(dataset$Level_0,
dataset$Level_1,
dataset$Level_2,
dataset$Level_3,
dataset$Level_4,
dataset$Level_5,
sep = "/")
g <- as.Node(dataset)
g <- as.igraph(g, directed=TRUE)
V(g)$color <- ifelse(dataset$color_thresh==1, "red", "green")
plot.igraph(g, vertex.label.color="black", vertex.label.dist=0, vertex.label.family="Helvetica", vertex.frame.color="white", vertex.size=25, layout=layout_as_tree)
The colors change when i sort the data frame by [color_thresh], but still doesn't give me the right colors. Any comments helping me to understand how the conditional coloring works is much appreciated! Thank you so much in advance.



colorsit could be done withV(g)$color[colors]and it will sort your colors according to the colors vector. - patL