我使用 igraph、hmisc 和矩阵包生成了一个基于 R 中微生物丰度相关性的微生物网络。现在我想在 Gephi 中工作。为此,我必须将我的数据传输到 Gephi。我试图从这些数据中准备 CSV 文件,但发现了这个错误:
write_delim(x, path, delim = ",", na = na, append = append, col_names = col_names, : is.data.frame(x) 不正确
这是我的完整代码:
library(igraph)
library(Hmisc)
library(Matrix)
library(writexl)
otu.table <- read.csv(file.choose(), header = T, row.names = 1)
tax <- read.csv(file.choose(), header = T, row.names = 1)
dim(otu.table)
otu.table.filter <- otu.table[ ,colSums(otu.table) >= 0.1]
dim(tax)
otu.cor <- rcorr(as.matrix(otu.table), type="spearman", )
otu.pval <- forceSymmetric(otu.cor$P)
sel.tax <- tax[rownames(otu.pval),,drop=FALSE]
all.equal(rownames(sel.tax), rownames(otu.pval))
p.yes <- otu.pval<0.001
r.val = otu.cor$r>0.8 # select all the correlation values
p.yes.r <- r.val*p.yes
p.yes.r <- abs(p.yes.r)>0.8 # output is logical vector
p.yes.rr <- p.yes.r*r.val
adjm <- as.matrix(p.yes.rr)
colnames(adjm) <- as.vector(sel.tax$Phylum)
rownames(adjm) <- as.vector(sel.tax$Phylum)
net.grph=graph.adjacency(adjm,mode="undirected",weighted=TRUE,diag=FALSE)
edgew<-E(net.grph)$weight
V(net.grph)$color <- tax$Phylum
bad.vs<-V(net.grph)[degree(net.grph) == 0]
net.grph <-delete.vertices(net.grph, bad.vs)
plot(net.grph,
vertex.size=8,
vertex.frame.color="black",
edge.curved=F,
edge.width=edgew,
layout=layout.fruchterman.reingold,
edge.color=ifelse(edgew > 1,"red","blue"),
vertex.label=NA,
vertex.label.color="black",
vertex.label.family="Times New Roman",
vertex.label.font=0.1)
write_csv(net.graph,"Documents\\R Analysis\\mydata.xlsx")
请告诉我如何将这些数据传输到 Gephi?