igraph 在尝试为边缘着色时简化了

igraph simplifies when trying to color edges

我有几种细胞类型,想展示它们之间的联系。我的问题是,如果我只使用 plot(all.cnx),它会显示所有连接。但是,如果我想添加 edge.color 等,那么它会简化图表。例如,从 "CT#1_3" 到其他细胞类型的连接。当我想显示所有边时,如何防止这种简化?

谢谢, 伊利亚斯

library("igraph")
my_cnxs = c("CT#1_0","CT#2_7","CT#1_2","CT#2_7","CT#1_3","CT#2_7","CT#1_5","CT#2_7","CT#1_6","CT#2_7","CT#1_0","CT#2_0","CT#1_0","CT#2_2","CT#1_0","CT#2_8","CT#1_2","CT#2_8","CT#1_3","CT#2_8","CT#1_5","CT#2_8","CT#1_6","CT#2_8","CT#1_2","CT#2_0","CT#1_2","CT#2_2","CT#1_3","CT#2_0","CT#1_3","CT#2_2","CT#1_5","CT#2_0","CT#1_5","CT#2_2","CT#1_6","CT#2_0","CT#1_6","CT#2_2","CT#1_1","CT#3_2","CT#1_1","CT#2_0","CT#1_1","CT#2_2","CT#1_2","CT#3_2","CT#1_3","CT#3_2","CT#1_5","CT#3_2","CT#1_6","CT#3_2","CT#3_2","CT#3_2","CT#3_2","CT#2_0","CT#3_2","CT#2_2","CT#2_8","CT#3_2","CT#2_8","CT#2_0","CT#2_8","CT#2_2","CT#1_1","CT#2_7","CT#1_2","CT#2_7","CT#1_3","CT#2_7","CT#1_5","CT#2_7","CT#1_6","CT#2_7","CT#3_2","CT#2_7","CT#2_8","CT#2_7")

my_edge_colors = c("green","green","green","green","green","green","green","green","green","green","green","green","black","black","black","black","black","black","black","black","red","red","red","red","red","red","red","red","red","red","red","red","red","red","red","red","red","red","red","red")

all_cell_colors = c("yellow3","red","skyblue","orange","violet","cyan3","gray80","green","darkgreen","pink","gold","cadetblue1","purple","darkkhaki","chocolate","darkred","aquamarine","darkslategray4","blue","cyan1")

names(all_cell_colors) = c("CT#4_0","CT#1_0","CT#1_1","CT#1_2","CT#1_3","CT#1_4","CT#1_5","CT#1_6","CT#1_7","CT#3_1","CT#3_2","CT#2_0","CT#2_1","CT#2_2","CT#2_3","CT#2_4","CT#2_5","CT#2_6","CT#2_7","CT#2_8")

all.cnx = graph(my_cnxs)
my_layout = layout_(all.cnx, nicely())
my.cx.names = names(edges(all.cnx)[[1]][1]) 
my_vertex_colors = all_cell_colors[match(my.cx.names, names(all_cell_colors))]
plot(all.cnx, layout = my_layout, edge.color = my_edge_colors, edge.arrow.size=0.4, vertex.color = my_vertex_colors, vertex.size=30,vertex.frame.color="black", vertex.label.color="black",vertex.label.cex=0.5, vertex.label.dist=0, edge.curved=0.2)
plot(all.cnx ,layout = my_layout)

由于edge.curved = 0.5,边缘重叠。它使所有边都具有相同的曲率,因此如果图形被简化,它就会出现,但实际上边在那里,只是完美重叠。

要恢复到您想要的效果,减少边缘曲线,您可以直接在 igraph 对象上使用函数 curve_multiple(),并将生成的向量传递给 edge.curve

plot(all.cnx, layout = my_layout,
     edge.color = my_edge_colors, edge.arrow.size=0.4,
     vertex.color = my_vertex_colors, vertex.size=30,vertex.frame.color="black",
     vertex.label.color="black",vertex.label.cex=0.5, vertex.label.dist=0,
     edge.curved = curve_multiple(all.cnx, .2)) # the default is 0.5

这只会在需要曲线的地方弯曲边缘,即会有重叠。如果您只是删除 edge.curved 参数,它会重置为默认值,从而导致边缘具有更大的曲率,但没有重叠。