fit0 = o2m(X = X, Y = Y, n = 2, nx = 2, ny = 2)
#模型返回数值讲解#
#Joint X scores:fit0$Tt#
#Joint X loadings: fit0$W.#
#Joint Y scores:fit0$U#
#Joint Y loadings: fit0$C.#
gene_looding <- as.data.frame(fit0$W.)
meta_looding <- as.data.frame(fit0$C.)
原始数据
#添加新列,并取第1列的绝对值#
abs <- NA
gene_looding <- cbind(gene_looding,abs)
meta_looding <- cbind(meta_looding,abs)
gene_looding[,3] <- abs(gene_looding[,1])
meta_looding[,3] <- abs(meta_looding[,1])
#按第3列abs降序#
gene_looding <- gene_looding[order(gene_looding$abs, decreasing= T), ]
meta_looding <- meta_looding[order(meta_looding$abs, decreasing= T), ]
colnames(gene_looding) <- c("pq1","pq2","abs")
colnames(meta_looding) <- c("pq1","pq2","abs")
绘制基因和代谢物前15个载荷值图
#绘制基因和代谢物前15个载荷值图#
gene_looding_15 <- gene_looding[1:15,]
meta_looding_15 <- meta_looding[1:15,]
#基因和代谢物载荷图结合起来#
mglooding_15 <- rbind(meta_looding_15[1:15,],gene_looding_15)
#添加新的一列,按组学进行归类#
Omics <- NA
Object <- NA
mglooding_15 <- cbind(Object,mglooding_15[,1:3],Omics)
mglooding_15[,1] <- row.names(mglooding_15)
row.names(mglooding_15)<- c(1:30)
mglooding_15[1:15,5] <- "Metabolome"
mglooding_15[16:30,5] <- "Transcriptome"
mglooding_15 <- mglooding_15[order( mglooding_15$Omics,-mglooding_15$pq1),]#根mglooding_15$Omics和mglooding_15$pq1排序#
mglooding_15$Object = factor(mglooding_15$Object,levels = mglooding_15$Object) # 将mglooding_15$Object列转换为因子#
#绘图#
pp <- ggplot(data = mglooding_15,mapping = aes(x=Object,y=pq1,fill=Omics))
#fill=Omics,意为Omics为填充色#
pp
pp+geom_bar(stat="identity")
pp+geom_bar(stat = "identity")+coord_flip() #Term太多了,反转一下x,y轴#
pp+geom_bar(stat = "identity")+coord_flip()+scale_x_discrete(limits=rev(levels(mglooding_15$Object)))#从大到小排列#
pp+geom_bar(stat = "identity")+coord_flip()+scale_x_discrete(limits=rev(levels(mglooding_15$Object)))+xlab("Features")+ylab("pq[1] Loading Scoer")
pp+geom_bar(stat = "identity")+coord_flip()+scale_x_discrete(limits=rev(levels(mglooding_15$Object)))+xlab("Features")+ylab("pq[1] Loading Scoer")+theme_bw()#切换成黑白背景的主题#
pp+geom_bar(stat = "identity")+coord_flip()+scale_x_discrete(limits=rev(levels(mglooding_15$Object)))+xlab("Features")+ylab("pq[1] Loading Scoer")+theme_bw()+ scale_fill_manual(values=c("green","blue"))#更改颜色#
library(eoffice)
topptx(filename = "O2PLS.pptx")#导出到ppt#
资料:https://www.dxy.cn/bbs/newweb/pc/post/37982590
https://mp.weixin.qq.com/s/rffQi_x0CxrU3ssOecFaNg