igraph简化了为边缘上色的过程

时间:2019-01-31 13:36:03

标签: r colors igraph simplify

我有几种单元格类型,想要显示它们之间的联系。我的问题是如果我仅使用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)

1 个答案:

答案 0 :(得分:2)

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

要返回所需的位置,减少边缘的弯曲,可以直接在curve_multiple()对象上使用函数igraph,然后将结果向量传递到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

enter image description here

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