I have a network in which I would like to highlight certain edges of node A
:
A
should be eg colored redA
should be green.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,
)
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")]
)
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.
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")))
)
or
plot(my_network_graph,
edge.curved = 0.2,
edge.color =with(my_network,ifelse(from %in% "A","red",ifelse(to == "A","green",NA)))
)
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.