0

I am very new to r and programming, so my knowledge is limited. I am using the igraph package and tkplot to make and present a directed acyclic graph. I managed to make a graph and I am trying to figure out how to add labels to each edge. My goal is to have a small annotation on the line between each vertices/vertex explaining their relationship.

I have tried inserting text as shown below:

text(-1, 0,"[1, 2, 3]")
text(0, 1,"[3, 5, 6]")

However, this text does not transfer to out of r with tkplot and is hard to line up with the lines between vertices.

this code gave me the exact graph I want minus the text between vertices.


g <- graph.formula("ATB" -+ "Microbiome",
                   "Microbiome" -+ "Inflammation A" -+ "IO Response",
                   "Microbiome" -+ "Inflammation B" -+ "IO Response",
                   "Microbiome" -+ "IO Response",
                   "ATB" -+ "IO Response",
                   "Corticosteroids" -+ "IO Response",
                   "Corticosteroids" -+ "Microbiome",
                   "PPI" -+ "IO Response",
                   "PPI" -+ "Microbiome",
                   "H2B" -+ "IO Response",
                   "H2B" -+ "Microbiome",
                   "NSAIDs" -+ "Microbiome",
                   "NSAIDs" -+ "Inflammation B",
                   "NSAIDs" -+ "IO Response",
                   "Corticosteroids" -+ "Inflammation A",
                      simplify = TRUE)

plot.igraph(g, size = 90)

tkplot(g)
Gopi
  • 620
  • 8
  • 16
mitch.9
  • 1
  • 1

1 Answers1

1

You can add labels to the edges by assigning an attribute "label" to each edge. You don't say what you want as the labels, so I arbitrarily assigning a letter code to each edge. Also, your plot statement includes a "size" parameter. That causes an error so I left it off. Did you mean "vertex.size"?

E(g)$label = LETTERS[1:ecount(g)]
plot(g)

graph with labeled edges

G5W
  • 36,531
  • 10
  • 47
  • 80