相关性图和密度图结合
library(ggplot2)
install.packages("ggpubr")
install.packages("ggExtra")
library(ggpubr)
library(ggExtra)
inputFile="input.txt"
gene1="MTMR14" #第一个基因名字
gene2="PRKCD" #第二个基因名字
# setwd("D:\\biowolf\\bioR\\22.cor")
#读取输入文件,提取基因表达量
rt=read.table("input2.txt",sep="\t",header=T,check.names=F,row.names=1)
x=as.numeric(rt[gene1,])
y=as.numeric(rt[gene2,])
#相关性分析
df1=as.data.frame(cbind(x,y))
corT=cor.test(x,y,method="spearman")
cor=corT$estimate
pValue=corT$p.value
p1=ggplot(df1, aes(x, y)) +
xlab(gene1)+ylab(gene2)+
geom_point()+ geom_smooth(method="lm",formula = y ~ x) + theme_bw()+
stat_cor(method = 'spearman', aes(x =x, y =y))
p2=ggMarginal(p1, type = "density", xparams = list(fill = "orange"),yparams = list(fill = "blue"))
#出图
pdf(file="cor.pdf",width=5,height=4.8)
print(p1)
dev.off()
#出图2
pdf(file="cor.density.pdf",width=5,height=5)
print(p2)
dev.off()
https://cran.r-project.org/web/packages/ggExtra/vignettes/ggExtra.html
本文作者:元元堂随笔
本文链接:https://www.cnblogs.com/yuanytsb/p/16788754.html
版权声明:本作品采用知识共享署名-非商业性使用-禁止演绎 2.5 中国大陆许可协议进行许可。
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步