O2PLS(绘制基因和代谢物前15个载荷值图)--R

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

  • 0
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

紫霄zixiao

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值