GGR绘图中热绘图标签中的上标

GGR绘图中热绘图标签中的上标,r,ggplot2,expression,superscript,R,Ggplot2,Expression,Superscript,早上好 phenolist2 pheno1 pheno2 pheno3 pheno4 pheno5 max.pheno1 pheno1 0.05475998 0.05055959 0.05056578 0.10330301 0.05026997 max.pheno2 pheno2 0.15743312 0.05036100 0.05151750 0.04880302 0.31008809 max.pheno3 ph

早上好

    phenolist2 pheno1 pheno2 pheno3 pheno4   pheno5
max.pheno1     pheno1    0.05475998        0.05055959   0.05056578  0.10330301 0.05026997
max.pheno2 pheno2    0.15743312        0.05036100   0.05151750  0.04880302 0.31008809
max.pheno3      pheno3    0.05458550        0.07672537   0.04043422  0.16845294 0.14268895
max.pheno4       pheno4    0.05484327        0.04391523   0.05151107  0.09521869 0.19776296
max.pheno5           pheno5    0.08658449        0.05183693   0.16292683  0.22369817 0.53630569
我正在绘制一张特定表型之间相关性的热图。我想为每个磁贴贴贴上R^2的标签,以便进行关联。 我有一个相关矩阵,max_all,如下所示:

    phenolist2 pheno1 pheno2 pheno3 pheno4   pheno5
max.pheno1     pheno1    0.05475998        0.05055959   0.05056578  0.10330301 0.05026997
max.pheno2 pheno2    0.15743312        0.05036100   0.05151750  0.04880302 0.31008809
max.pheno3      pheno3    0.05458550        0.07672537   0.04043422  0.16845294 0.14268895
max.pheno4       pheno4    0.05484327        0.04391523   0.05151107  0.09521869 0.19776296
max.pheno5           pheno5    0.08658449        0.05183693   0.16292683  0.22369817 0.53630569
否则,我的代码如下:

    phenolist2 pheno1 pheno2 pheno3 pheno4   pheno5
max.pheno1     pheno1    0.05475998        0.05055959   0.05056578  0.10330301 0.05026997
max.pheno2 pheno2    0.15743312        0.05036100   0.05151750  0.04880302 0.31008809
max.pheno3      pheno3    0.05458550        0.07672537   0.04043422  0.16845294 0.14268895
max.pheno4       pheno4    0.05484327        0.04391523   0.05151107  0.09521869 0.19776296
max.pheno5           pheno5    0.08658449        0.05183693   0.16292683  0.22369817 0.53630569
    tmp_Rsq <- melt(max_all)

tmp_Rsq <- ddply(tmp_Rsq, .(variable), transform, rescale=rescale(value))

labels_Rsq <- expression(paste(R^2, " = ", format(tmp_Rsq$value, digits=2), sep=""))

ggplot(tmp, aes(variable, phenolist2)) + 
  geom_tile(aes(fill =-log10(value)), colour = "white") +
  geom_text(aes(label=as.character(labels_Rsq), parse = TRUE, size=4)) +
  scale_fill_gradientn(colours = myPalette(101), name="-log10(P)", limits=c(0 , 3.5)) +
  theme(axis.title.x = element_blank(), axis.title.y=element_blank(),
        plot.title=element_text(size=20))+
  theme(axis.text = element_text(colour="black", face="bold"))
我的问题是我无法写出表达式,因此2是R的上标。 例如,我意识到这个网站上有很多问题都在解决类似的问题,但我无法将这些答案中建议的解决方案应用到我的案例中,因为我一直在尝试使用标签向量

    phenolist2 pheno1 pheno2 pheno3 pheno4   pheno5
max.pheno1     pheno1    0.05475998        0.05055959   0.05056578  0.10330301 0.05026997
max.pheno2 pheno2    0.15743312        0.05036100   0.05151750  0.04880302 0.31008809
max.pheno3      pheno3    0.05458550        0.07672537   0.04043422  0.16845294 0.14268895
max.pheno4       pheno4    0.05484327        0.04391523   0.05151107  0.09521869 0.19776296
max.pheno5           pheno5    0.08658449        0.05183693   0.16292683  0.22369817 0.53630569

非常感谢您的帮助。

解析需要在aes之外,标签需要是字符向量

    phenolist2 pheno1 pheno2 pheno3 pheno4   pheno5
max.pheno1     pheno1    0.05475998        0.05055959   0.05056578  0.10330301 0.05026997
max.pheno2 pheno2    0.15743312        0.05036100   0.05151750  0.04880302 0.31008809
max.pheno3      pheno3    0.05458550        0.07672537   0.04043422  0.16845294 0.14268895
max.pheno4       pheno4    0.05484327        0.04391523   0.05151107  0.09521869 0.19776296
max.pheno5           pheno5    0.08658449        0.05183693   0.16292683  0.22369817 0.53630569
labels_Rsq <- paste0("R^2 ==", format(tmp_Rsq$value, digits=2))

> head(labels_Rsq)
[1] "R^2 ==0.055" "R^2 ==0.157" "R^2 ==0.055" "R^2 ==0.055" "R^2 ==0.087" "R^2 ==0.051"

ggplot(tmp_Rsq, aes(variable, phenolist2)) + 
  geom_tile(aes(fill =-log10(value)), colour = "white") + 
  geom_text(aes(label=as.character(labels_Rsq)), parse = TRUE, size=4) +
 # scale_fill_gradientn(colours = myPalette(101), name="-log10(P)", limits=c(0 , 3.5)) +
  theme(axis.title.x = element_blank(), axis.title.y=element_blank(), 
        plot.title=element_text(size=20))+
  theme(axis.text = element_text(colour="black", face="bold"))