服务热线
178 0020 3020
#设置当前工作目录,所下载的数据或者生成的数据都在如下目录下
setwd("D:/geo/GSE70689/")
#计算两个基因的相关性,依然采用CBD_LPS的数据
mRNA = read.csv("exprSet.csv", header = T, row.names = 1)
#本mRNA里面的表达数据是经过log2转换的,因此计算相关性的时候应该转换回来
exprSet = mRNA^2
#计算Gene1和Gene2的相关性
Gene1 = "Mt2"
Gene2 = "Vegfa"
data = data.frame("X"=as.numeric(exprSet[row.names(exprSet)==Gene1,]),"Y"=as.numeric(exprSet[row.names(exprSet)==Gene2,]))
pdf(file = "cor.pdf", width =4, height = 4)
cor_plot <- function(x,y){
plot(x,y, xlab = Gene1, ylab = Gene2, pch=20)
model = lm(y ~ x)
summary(model)
int = model$coefficient["(Intercept)"]
slope =model$coefficient["x"]
abline(int, slope,
lty=1, lwd=2, col="red")
r= format(cor(x,y),digits = 4)
p= format(cor.test(x,y)$p.value,digits = 4)
#title(main = paste0('p value=',p),sub = paste0('correlation=',r))
legend("topright",legend = c(paste("R=",r),paste("P=",p)))
}
cor_plot(x=data$X,y=data$Y)
dev.off()
附件