inst2 = c(2, 3, 4, 5, 6)
motherinst2 = c(7, 8, 2, 10, 11)
km = c(20, 30, 40, 25, 60)
df2 = data.frame(inst2, motherinst2)
df2 = cbind(df2, km)
g2 = graph_from_data_frame(df2)
tkplot(g2)
我将如何仅向图中的根顶点和终端顶点添加标签?我知道它会涉及到这个功能,但是你会如何设置它?假设图形对象被称为“g”,或者其他明显的名称。
vertex.label =
@eipi1o 的解决方案很好,但 OP 说“我发现很难有效地应用于我的大数据集。”我怀疑问题在于找到哪些中间节点的名称应该被删除。我将继续@eipi10 的例子。由于我的答案是基于他的,如果您支持我的答案,请也支持他的答案。
您可以使用neighbors
函数来确定哪些点是源点和汇点。其他一切都是中间节点。
## original graph from eipi10
g = graph_from_edgelist(cbind(c(rep(1,10),2:11), c(2:21)))
## Identify which nodes are intermediate
SOURCES = which(sapply(V(g), function(x) length(neighbors(g, x, mode="in"))) == 0)
SINKS = which(sapply(V(g), function(x) length(neighbors(g, x, mode="out"))) == 0)
INTERMED = setdiff(V(g), c(SINKS, SOURCES))
## Fix up the node names and plot
V(g)$name = V(g)
V(g)$name[INTERMED] = ""
plot(g)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)