[英]Color edges in a directed network with igraph
I have a network in which I would like to highlight certain edges of node A
:我有一个网络,我想在其中突出显示节点
A
某些边缘:
A
should be eg colored redA
出发的方向应该是红色的A
should be green.A
方向应该是绿色的。A
should not be printed at all.A
连接的其他边。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
.到目前为止,我可以突出显示
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).我想让边缘
D -> A
和C -> A
在蓝色的 plot 与边缘A -> B
和A -> C
。
The list of edges should not be hard-coded.边列表不应该是硬编码的。 Only
A
should be given and the others should be calculated automatically.只应给出
A
,其他应自动计算。
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)))
)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.