问题
i have a graph where one of the edge attribute is the correlation between 2 vertices. I would like to colour the edges on my plot differently according to whether the correlation is positive or negative. I tried using edge.color=c("red","blue")[E(mygraph)$correlation>=0] in the plot attributes but i end up with only the first 2 edges showing, one red, one blue, and no others... See this simplified example:
myedges<-data.frame(From=c("item1","item1","item1","item2","item2","item3"),
To=c("item2","item3","item4","item3","item4","item4"),
correlation=c(0.4,0.1,-0.6,-0.3,0.5,0.8))
mygraph<-graph_from_data_frame(myedges, directed=FALSE)
plot(mygraph,
edge.width=E(mygraph)$correlation*50,
edge.color=c("red","blue")[E(mygraph)$correlation>=0])
what am i doing wrong...?
来源:https://stackoverflow.com/questions/35315988/r-igraph-colour-edge-according-to-logical-flag