图:从布局中删除顶点 [英] igraph: Remove vertices from layout

查看:39
本文介绍了图:从布局中删除顶点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在4个步骤(即不同的时间点)上创建图形的可视化.我的顶点(节点)的位置应始终保持不变(使用完整图形的位置).我想要的只是从R igraph图中删除一些顶点.顶点名称更改似乎是个问题.

I want to create a visualization of a graph at 4 steps, i.e. different points in time. The positions of my vertices (nodes) should always stay the same (use the positions of the full graph). All I want is to remove some vertices from the R igraph graph. What seems to be an issue is that the vertices names change.

# Erdos
par(mfrow=c(1,3))
g <- erdos.renyi.game(20, 1/20)
locs <- layout.fruchterman.reingold(g)
V(g)$name <- V(g)
# In the original file, vector names look like this (not "1,2,3,4...):
V(g)$name <- as.vector(c(8,9,3,5,13,6,7,1,2,18,11,12,16,14,15,4,17,10,20,19))
V(g)$name

plot(g, 
     layout=locs, 
     main="Original")

# Remove a few vertices
removals1 <- c("12","2","9","11","4")
g2 <- delete.vertices(g,removals1)
plot(g2, 
     layout=locs[-as.numeric(removals1),], 
     main="Removals")

# Remove some more
removals2 <- c("15","14","7","8","5","19","10")
g3 <- delete.vertices(g2,removals2)
plot(g3, 
     layout=locs[-as.numeric(c(removals1,removals2)),], 
     main="More Removals")

我很高兴在这里找到解决方案.也许,还有一种比上述解决方案更优雅的解决方案.谢谢!

I would be really happy to find a solution here. Maybe, there are also far more elegant solution as the one above. Thanks!

推荐答案

与其使用删除(以某种方式移动顶点)(我什至无法完全覆盖图形,不能承受标签)代替删除,最好使用 ductive_subgraph .我不知道为什么会出现这种情况,但这似乎行得通.

Instead of using the delete which was somehow moving the vertices around (I couldn't even completly overlay the graph, labels not withstanding), it is better to use induced_subgraph. I do not why this is the case but it seems to work.

# Erdos
g <- erdos.renyi.game(20, 1/20)
locs <- layout.fruchterman.reingold(g)
V(g)$name <- V(g)
# In the original file, vector names look like this (not "1,2,3,4...):
V(g)$name <- as.vector(c(8,9,3,5,13,6,7,1,2,18,11,12,16,14,15,4,17,10,20,19))
V(g)$name

par(mfrow=c(1,3))
plot(g, 
     layout=locs, 
     main="Original")

# Remove a few vertices
removals1 <- c("12","2","9","11","4")
g2 <- induced_subgraph(g, V(g)[-as.numeric(removals1)])
plot(g2, 
     layout=locs[-as.numeric(removals1),], 
     main="Removals")

# Remove some more
removals2 <- c("15","14","7","8","5","19","10")
g3 <- induced_subgraph(g, V(g)[-as.numeric(c(removals1, removals2))])
plot(g3, 
     layout=locs[-as.numeric(c(removals1,removals2)),], 
     main="More Removals")

这篇关于图:从布局中删除顶点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆