获取igraph图中边缘标签的子集

时间:2019-01-04 05:21:00

标签: r igraph

给出以下data.frame

df <- structure(list(POP1 = c("ES13-15", "ES13-15", "ES16-18", "ES16-18", 
"ES19-21", "ES19-21", "ES22-24", "ES22-24", "ES25-27", "ES25-27", 
"ES28-30", "ES28-30", "ES31-33", "ES31-33", "ES34-36", "ES34-36", 
"ES37-38", "SA1-3", "SA4-6", "SA7-9", "SA10-12", "SA13-15", "SA16-18", 
"SA19-21"), POP2 = c("SA1-3", "ES16-18", "SA1-3", "ES19-21", 
"SA4-6", "ES22-24", "SA7-9", "ES25-27", "ES28-30", "SA10-12", 
"SA13-15", "ES31-33", "SA16-18", "ES34-36", "SA19-21", "ES37-38", 
"SA22-25", "SA4-6", "SA7-9", "SA10-12", "SA13-15", "SA16-18", 
"SA19-21", "SA22-25"), FST = c(0.0129, 0.0109, 0.0176, 0.012, 
 0.0564, 0.0275, 0.0193, 0.0108, 0.029, 0.0416, 0.0398, 0.0061, 
 0.0541, 0.0134, 0.0402, 0.0205, 0.024, 0.0081, 0.0035, 0.02, 
 0.0094, 0.0095, 0.0161, 0.0199)), row.names = c(NA, 24L), class = 
 "data.frame")

df的打印片段如下:

POP1    POP2    FST
ES13-15   SA1-3 0.0129
ES13-15 ES16-18 0.0109
ES16-18   SA1-3 0.0176
ES16-18 ES19-21 0.0120
ES19-21   SA4-6 0.0564
ES19-21 ES22-24 0.0275
ES22-24   SA7-9 0.0193
ES22-24 ES25-27 0.0108
ES25-27 ES28-30 0.0290

这是我的图形的代码:

 g3 <- graph_from_data_frame(d = df3[,c(1,2)],directed = F)

 E(g3)$weight = df3$FST

 plot(g3,
 vertex.color=ColMap,
 vertex.frame.color="white",
 vertex.label.color="black",
 vertex.label.cex = .6,
 layout=layout.auto(g3),
 edge.label = E(g3)$weight,
 edge.label.cex = 0.6)

weight属性向量如下:

E(g3)$weight <- c(0.0129, 0.0109, 0.0176, 0.012, 0.0564, 0.0275, 0.0193, 
0.0108, 0.029, 0.0416, 0.0398, 0.0061, 0.0541, 0.0134, 0.0402, 0.0205, 
0.024, 0.0081, 0.0035, 0.02, 0.0094, 0.0095, 0.0161, 0.0199)

我的没有权重属性向量的图看起来几乎是我想要的样子。enter image description here

我唯一的问题是当我发出edge.label = E(g3)$weight命令时,我得到了图形每个边缘的所有数字,但是我只希望具有不同颜色(紫色和绿色)之间的边缘值)。

我试图排除权重向量的某些索引,例如:E(g3)$weight[c(-4,-6,-8,-9,-12,-14,-16,-18:-24)],因为这些索引不是我想要的索引,但它不起作用。

有没有一种方法可以只在图表上打印edge.label中的一部分而隐藏其他部分?

0 个答案:

没有答案