R:如何覆盖来自不同数据的热图上的文本?

问题描述

我被要求绘制一个热图,以一种简单的方式显示大量的 p 值。问题是我的老板想用 log(p) 值给图块着色并用 p 值覆盖它们。我设法覆盖了热图上的值(log 或 p),但无法使用来自另一个数据帧的数据进行覆盖。 这些是我的数据(已缩短)和代码:

covariate   HbA1c   FPG     Weight  SBP 
Age         0.867   0.928   0.001   0.001   
Sex         0.428   0.565   0.001   0.790   
BMI         0.491   0.435   0.001   0.001   


data <- read.delim(file="hm.txt",sep = "\t")    
df.log <- log(data[,2:12])         #the real data has 12 columns
df.log <- round(df.log,digits=3)

data.cov <- data$covariate
df <- cbind(data.cov,df.log)
df$data.cov = factor(df$data.cov,unique(df$data.cov))

df <- gather(df,key = "factor",value = "pvalue",-data.cov)
df$factor = factor(df$factor,unique(df$factor))

heatmap <- ggplot(df) +
  aes(x = data.cov,y = factor,fill = pvalue,label=pvalue) +
  geom_tile() +
  scale_fill_gradient(low = "#ffffff",high = "#595959",limits=c(-7,0)) + 
  theme_linedraw(base_size = 15) +
  geom_text() +
  theme(text=element_text(family="Roboto"))+
  theme(legend.position = "top",legend.key.width = unit(1.7,"cm"),legend.title=element_blank())+
  theme(axis.text.x=element_text(angle=90,vjust =0.2))
    

这可能只是一个geom_text问题,但我似乎无法成功解决

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)