简体   繁体   中英

Plotting a graph- igraph

I wanted to print two vertex name on one plot. How to do it? I have two data frames.

I tried it giving in the plot code:

vertex.label=c(V(siec_ace_2)$inequality,V(siec_ace_2)$ID) 

but it is not working.

data_con<-data.frame(
  "ID"=c("J","E","H","A","F","B","G","I","D","C"),
  "inequality"=c("13w+11x+8y+11z<=M","13w+12x+10y+9z<=M","13w+7x+8y+10z<=M"
          ,"12w+11x+12y+8z<=M","9w+7x+9y+12z<=M","7w+7x+10y+8z<=M"
          ,"8w+12x+8y+7z<=M","9w+13x+9y+7z<=M","7w+8x+13y+11z<=M","13w+7x+11y+10z<=M")
)

data_edges<-data.frame(
  "from"=c("J","J","E","E","E","H","H","H","A","A","A","F",
           "B","B","B","B","G","G","G","G","G","G","I","I","I","D","D","C","C"),
  "to"=c("H","G","J","A","F","E","A","B","J","F","B","E",
           "H","A","G","D","J","H","A","B","D","C","F","G","C","B","G","G","I"),
  "value"=c(4,9,4,4,4,5,4,2,6,3,6,5,3,5,5,3,8,4,5,4,2,5,8,6,3,2,3,3,3)
)

siec_ace <- graph_from_data_frame(d = data_edges , vertices= data_con, directed=T)
siec_ace_2 <- simplify(siec_ace, remove.multiple = F, remove.loops = T) 
plot(siec_ace_2, edge.arrow.size=.5, vertex.label.color="gray10", 
  edge.label = E(siec_ace_2)$value, 
  vertex.label = c(V(siec_ace_2)$inequality, V(siec_ace_2)$ID)  )

This code plots only one value. I want two values: inequality and ID.

Thanks in advance.

A vertex can only have one label on the plot. You can paste() together different values to combine values if you like. Here I put a newline between the values to it appears on a second line. Also, I think you want the node name rather than ID

plot(siec_ace_2, edge.arrow.size=.5, vertex.label.color="gray10", 
     edge.label = E(siec_ace_2)$value, 
     vertex.label = paste(V(siec_ace_2)$inequality, V(siec_ace_2)$name, sep="\n")  )

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