我正在改写/重新格式化我以前的帖子。
我有一个定向网络,具有不同的节点属性和边缘属性。一些节点具有完全相同的连接。所以我想合并/合并/收缩它们。我希望这样的东西,即所谓的嵌套网络,但最好带箭头。 http://manual.cytoscape.org/en/stable/Nested_Networks.html
我发现了几乎可以完成这项任务的两个选项。让我来看看吧。
line = line.Replace("\0", "");
选项1: library(igraph)
library(dplyr)
library(RedeR)
net <- graph_from_data_frame(data.frame(
from = c("a", "a", "a", "b", "c", "d"),
to = c("b", "c", "d", "e", "e", "e"),
type = c("activation","activation","activation",
"inhibition","inhibition","inhibition")
),
directed = T)
V(net)$color <- c("grey", "forestgreen", "firebrick", "navyblue", "grey")
plot(net, layout = layout_as_tree)
# as you can see, colored nodes, `b,c,d`, are equally connected by `a` and `e`.
igraph::contract
选项1可能看起来不错。可以保留边缘属性。但是当合并节点的数量,这里即。 {4}大于{4},pie.shaped节点实际上不可读。此外,它们之间可能还存在内部联系,这些内部联系无法实现。
选项2:net.c <- contract(net, c(1,2,2,2,3), vertex.attr.comb = toString)
# net.c <- simplify(net.c, remove.multiple = T, remove.loops = T, edge.attr.comb = "sum")
# somehow sometimes `simplify` crashed my R, so I did this instead.
net.c <- igraph::as_data_frame(net.c) %>% unique %>% graph_from_data_frame(., directed = T)
# this kept edge attributes while lost vertex color, which is understandable.
# i recreated node color, using pie.shape
plot(net.c,
vertex.shape = c("circle", "pie", "circle"),
vertex.pie = list(c(1,1,1)),
vertex.pie.color = list(c("forestgreen", "firebrick", "navyblue"))
)
b,c,d
RedeR::nestNodes
包含在一个圆圈中,这非常好。但在rdp <- RedPort()
calld(rdp)
resetd(rdp)
addGraph(rdp, net, parent="a")
nestNodes(rdp, nodes = c("b", "c", "d"), nestImage = "plain",
isAssign = F,
gscale = 25)
mergeOutEdges(rdp)
之后,容器外的箭头将被删除。一件微不足道的事情是我无法弄清楚如何删除容器标签 N0 ,因为参数b,c,d
似乎不起作用。
这是我能找到的两个选项。 有什么建议我可以从这里改进吗? 谢谢。