3

我有一个这样的数据框:

1 2
2 3
4 5
....

现在,我使用库 igraph 使用以下代码在 R 中绘制此图:

wt=read.table("NP7.txt")
wt1=matrix(nrow=nrow(wt), ncol=2)     
wt1=data.frame(wt1)
wt1[,1:2]=wt[,1:2]      
write.table(wt1,"test.txt")
library(igraph)
wt=read.table("test.txt")
wg7 <- graph.edgelist(cbind(as.character(wt$X1), as.character(wt$X2)),
                 directed=F)
sum(clusters(wg7)$csize>2)        
plot(wg7)
a <- largest.clique(wg7)

现在,在运行此代码时,我得到了图形的图和形成最大集团的值。但是,如果我想要那个实际最大的集团的情节,我该怎么做?谢谢!

4

1 回答 1

4

这是一个例子:

library(igraph)

# for reproducibility of graphs plots (plot.igraph uses random numbers)
set.seed(123)

# create an example graph
D <- read.table(header=T,text=
'from to
A B
A C
C D
C F
C E
D E
D F
E F')

g1 <- graph.data.frame(D,directed=F)

# plot the original graph
plot(g1)

# find all the largest cliques (returns a list of vector of vertiex ids)
a <- largest.cliques(g1)

# let's just take the first of the largest cliques
# (in this case there's just one clique)
clique1 <- a[[1]]

# subset the original graph by passing the clique vertices
g2 <- induced.subgraph(graph=g1,vids=clique1)

# plot the clique
plot(g2)

图 1(原始图):

图 1

情节2(集团):

集团


编辑 :

正如@GaborCsardi 正确指出的那样,没有必要对图进行子集化,因为集团是一个完整的图。这可能比induced.subgraph

g2 <- graph.full(length(clique1))
V(g2)$name <- V(g1)$name[clique1]
于 2014-10-06T19:00:50.927 回答