【发布时间】:2021-02-02 10:37:42
【问题描述】:
我被要求绘制一张热图,以一种简单的方式显示大量 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 的问题,但是好像解决不了
【问题讨论】:
标签: r ggplot2 heatmap geom-text