简体   繁体   中英

Edge conditions in igraph in R

I am working on igraph trying to make my own visualization of the graph taken from KEGG xml. I have retreived an adjacency matrix for the graph and an edge list.Now I have a few conditions for my edges for example I have inhibition, activation and binding association (not weighted). Now I want to color the edges differently and I also want the shape of the edges differently for each condition. For example an edge with arrow and green in color for activation. An edge with a vertical lie after edge and red in color for inhibition. And maybe a dotted line for binding association.

My edge List named reactions looks like this

    > entry1    entry2  name 

    > 59         62     activation
    > 62         57     Inhibition
    > 61         60     binding association
    > 53         42     activation  

My nodes are in the form of an directed adjacency matrix.

  plot(G,vertex.shape= "rectangle", edge.arrow.size=.3, edge.color=ifelse(reactions$name =="activation", "green", "red"),vertex.color="gold", vertex.size2=1,vertex.frame.color="gray", vertex.label.color="black", vertex.label.cex=1, vertex.label.dist=0.5, edge.curved=0.2) 

I was just tryin to check if the code works for activation first and then i deal with other conditions but all my edges are green not just the activation ones.

Could some body help me with this. I tried using edge.color with ifelse but don't really know how to use it.

Instead of referencing the variable with your conditions in the data frame, try referencing the data in the graph itself. Here I can recreate your graph:

library(igraph)

d <- data.frame(ego=c('59', '62', '61', '53'), alter=c('62', '57', '60', '42'), status=c("activation","Inhibition","binding association","activation"))

G <- graph_from_data_frame(d)

Lets see what the graph includes:

str(G)

The (e/c) is telling us that status is a characteristic of the edges, just what we want to condition the color and or shape of the edges.

plot(G)

plot(G, vertex.shape= "rectangle", edge.arrow.size=.3, edge.color=ifelse(E(G)$status =="activation", "green", "red"), vertex.color="gold", vertex.size2=1, vertex.frame.color="gray", vertex.label.color="black", vertex.label.cex=1, vertex.label.dist=0.5, edge.curved=0.2) 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM