This is a test version of Biostars. For the public version, visit https://www.biostars.org.
highlight cells in a heatmap using ggplot2

Hello all, I have gotten a correlation heatmap with a data set that looks like the one below. The column “corrsing” in the data set contains values that indicate if a correlation coefficient is or not significant, so by using this column I would like to get a heatmap in which all the coefficients with values <2 in the column "corrsig" being colored white or another color. eg the cells for A-D and C-D would be white. Any suggestion to get that?

var1   var2  corr   corrsig
 A     B     0.8    3.1
 A     C    -0.3    2.63
 A     D     0.25   1.5
 B     C    -0.75   2.9
 B     D     0.6    2.1
 C     D     0.1    0.82

The code I am using is as follow:

ggheatmap <- ggplot(data = cordata, aes(var2, var1, fill = corr))+
  geom_tile(color = "white") + 
  scale_fill_gradient2(low ="blue", high ="red", mid ="white", midpoint =  0, limit = c(-1,1), space = "Lab", name="cor") + theme_minimal() + 
  theme(axis.title.x = element_text(angle = 0, vjust = 0.5, size = 15, hjust = 0.5), axis.text.x = element_text(angle = 0, vjust = 1, size = 15, hjust = 1))+
  theme(axis.title.y = element_text(angle = 90, vjust = 0.5, size = 15, hjust = 0.5), axis.text.y = element_text(angle = 0, vjust = 1, size = 15, hjust = 1))+
  coord_fixed()
print(ggheatmap)

ggheatmap+ 
  geom_text(aes(var2, var1, label = corr), color = "black", size = 5) +
  theme(  
    panel.grid.major = element_blank(),
    panel.border = element_blank(),
    panel.background = element_blank(),
    axis.ticks = element_blank(),
    legend.justification = c(1, 0),
    legend.position = c(0.6, 0.7),
    legend.direction = "horizontal")+
    guides(fill = guide_colorbar(barwidth = 7, barheight = 1,
                           title.position = "top", title.hjust = 0.4))

If that is possible any help will be appreciate.

heatmap ggplot2

0 answers

No answers yet.

Log in to answer this question.