如何为自循环着色?

时间:2017-10-24 10:26:39

标签: r igraph

我正试图在我的igraph网络中仅为自循环边缘着色。以下是我的数据样本。

head(network.txt)
From    To
A   A
A   B
A   C
A   D
B   A
B   B
B   C
B   D
C   A
C   B
C   C
C   D
D   A
D   B
D   C
D   D 

这是网络代码

df=read.table("network.txt", header = TRUE)

nodes=unique(df$From)

g=graph_from_data_frame(df)

plot(g, edge.arrow.size=0.2, vertex.color="gold", vertex.size=15, vertex.frame.color="gray", vertex.label.color="black", vertex.label.cex
     =0.5, vertex.label.dist=0, edge.curved=0.2, edge.color="black", main="Adult CRC network", layout=layout_in_circle)

> head(E(g))
+ 6/16 edges from ea19d0a (vertex names):
[1] A->A A->B A->C A->D B->A B->B

Here is the output network

另外,无论如何要将循环保持在网络之外吗?

1 个答案:

答案 0 :(得分:2)

你可以这样做:

library(igraph)
g <- make_full_graph(10, loops = TRUE)
plot(g, edge.color = ifelse(is.loop(g), "red", "grey"))

enter image description here