r - igraph:从布局中删除顶点

标签 r igraph vertices

我想按 4 个步骤创建图形的可视化,即不同的时间点。我的顶点(节点)的位置应该始终保持不变(使用完整图表的位置)。我只想从 R igraph 图中删除一些顶点。似乎有问题的是顶点名称发生了变化。

# 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")

如果能在这里找到解决方案,我会非常高兴。也许,还有比上面更优雅的解决方案。谢谢!

最佳答案

与其使用以某种方式移动顶点的删除(我什至无法完全覆盖图形,标签无法承受),不如使用 induced_subgraph。我不知道为什么会这样,但它似乎有效。

# 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")

enter image description here

关于r - igraph:从布局中删除顶点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41020944/

相关文章:

r - 如何保存 igraph 图

opengl - 如何对用三角形绘制的 "perfect cube"进行纹理处理?

r - 使用交叉验证比较不同预测变量的线性回归模型的性能

r - 对 data.frames 列表进行子集并返回 data.frames 列表

r - 斐波那契函数

python - 创建图时获取边权重

r - igraph - 邻居作为子图 - make_ego_graph() 作为单个图

r - 通过远离 for 循环来提高性能

three.js - 如何在Three.JS中获取obj模型对象的顶点?

opengl - 从顶点数据中获取像素法线