1

I have a network in which I would like to highlight certain edges of node A:

  • directions going out of A should be e.g. colored red
  • directions goint to A should be green.
  • all other edges not connected with node A should not be printed at all.
library('igraph')

my_network <- read.table(
  header=TRUE,
  sep=",",
  text="
from,to
A,B
A,C
C,D
D,A
C,A")

set.seed(1234)
my_network_graph <- graph_from_data_frame(my_network)
plot(my_network_graph,
     edge.curved= 0.2,
)

enter image description here

So far I can highlight those edges going out of A.

plot(my_network_graph,
     edge.curved= 0.2,
     edge.color = c(NA, "red")[1+ (my_network$from == "A")]
      )

enter image description here

I would like to have the edges D -> A and C -> A in blue in the same plot as with the edges A -> B and A -> C (in red).

The list of edges should not be hard-coded. Only A should be given and the others should be calculated automatically.

lukascbossert
  • 375
  • 1
  • 11

1 Answers1

1

You can try the code below

plot(my_network_graph,
  edge.curved = 0.2,
  edge.color =with(my_network,ifelse(from %in% "A","red",ifelse(from %in% c("C","D") & to == "A","blue","grey")))
)

enter image description here

or

plot(my_network_graph,
  edge.curved = 0.2,
  edge.color =with(my_network,ifelse(from %in% "A","red",ifelse(to == "A","green",NA)))
)

enter image description here

ThomasIsCoding
  • 96,636
  • 9
  • 24
  • 81