R igraph colour edge according to logical flag

て烟熏妆下的殇ゞ 提交于 2019-12-24 13:04:04

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!