Superscripts in heat plot labels in ggplot r

后端 未结 1 1549
醉话见心
醉话见心 2021-01-23 06:17

Good morning,

I am making a heat map in ggplot of correlations between specific phenotypes. I would like to label each tile with the R^2 for the association.
I have

1条回答
  •  一整个雨季
    2021-01-23 06:56

    Parse needs to be outside the aes, and the labels need to be a character vector.

    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"))
    

    0 讨论(0)
提交回复
热议问题