想做相关性热图
pacman::p_load(tidyverse,psych,reshape,ggtree,aplot)
table1<-read.table("C:\\Users\\Administrator\\Desktop\\TG TGS30.txt",header=T,sep="\t",check.names = F,row.names = 1)
table2<-read.table("C:\\Users\\Administrator\\Desktop\\TG TGSjun.txt",header = T,sep = "\t",check.names = F,row.names = 1)
pp <- corr.test(table1,table2,method="pearson",adjust = "fdr")
cor <- pp$r
pvalue <- pp$p
#根据P值用循环将P值做成*
myfun <- function(pval) {
stars = ""
if(pval <= 0.001)
stars = "***"
if(pval > 0.001 & pval <= 0.01)
stars = "**"
if(pval > 0.01 & pval <= 0.05)
stars = "*"
if(pval > 0.05 & pval <= 0.1)
stars = ""
stars
}
#对数据进行格式转换适用于ggplot2绘图
heatmap <- melt(cor) %>% rename(replace=c("X1"="sample","X2"="gene",
"value"="cor")) %>%
mutate(pvalue=melt(pvalue)[,3]) %>%
mutate(signif = sapply(pvalue, function(x) myfun(x)))
Error in mutate()
:
! Problem while computing signif = sapply(pvalue, function(x) myfun(x))
.
Caused by error in if (pval <= 0.001) ...
:
! missing value where TRUE/FALSE needed
Run rlang::last_error()
to see where the error occurred.