【问题标题】:How to keep position of nodes in igraph + R如何在 igraph + R 中保持节点的位置
【发布时间】:2016-05-23 05:05:27
【问题描述】:

如果我有下图并用向量设置节点的位置坐标:


library(igraph)
library(Cairo)

g9<- graph(c(0,1,0,2,0,3,1,4,1,2,3,4,3,5,4,5,5,2),n=6,dir=FALSE)
V(g9)$name<-c(1:6)
V(g9)$label<-V(g9)$name
coords <- c(0, 0, 1.00000000000000, 0,0.500000000000000, 0.866025403784439, 0.300000000000000, 0.200000000000000, 0.441421356237309, 0.341421356237310,0.248236190979496,0.393185165257814)
coords <- matrix(coords, 6,2,byrow=T)
plot(g9,layout=coords)

现在如果我添加以下代码,我必须重新设置坐标布局:


vc<-c(0,1,1,2,2,3,3,1)
gp<-graph(vc,dir=FALSE);
listSub<-graph.get.subisomorphisms.vf2(g9,gp)

m<-matrix(c(unlist(listSub)),length(listSub),length(unique(vc)),byrow=T)
md<-m[!duplicated(m[,1]),]

g<-delete.vertices(g9,c(m[1,2]))

dev.new()

coord <- c(0, 0, 1.00000000000000, 0,0.500000000000000, 0.866025403784439, 0.441421356237309, 0.341421356237310,0.248236190979496,0.393185165257814)
coord <- matrix(coord, 5,2,byrow=T)
plot(g,layout=coord)

如何将这些布局位置设为默认位置——这样我就可以在不丢失每个名称的相应位置的情况下对图形结构进行修改?


【问题讨论】:

    标签: r igraph


    【解决方案1】:

    你可以保留最初的coord 矩阵 并且只提取子图所需的行。

    plot(g9, layout = coords[ V(g9)$name, ])
    plot(g , layout = coords[  V(g)$name, ])
    

    【讨论】:

      猜你喜欢
      • 2016-02-08
      • 2012-05-06
      • 2020-07-19
      • 2021-08-17
      • 2013-03-23
      • 2022-01-21
      • 2023-01-14
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多