I want to put asterisks in the heat map for P-values < 0.05. I have a separate spreadsheet with the P-values that I read into R and subsequently the heat map, however, the function i'm using doesn't seem to place the asterisks in the right cells. In the Figure below, for example, there are no P-values attached to the rho = 0 cells, and yet there are asterisks placed there.
Spreadsheet is shown below. For all P-values that are NA, I put in "1" to avoid an error. If there's a better way to do this on top of fixing the placements of the asterisks, please let me know.
The code that i'm using is as follows:
library(circlize)
library(ComplexHeatmap)
library(Hmisc)
sx_syn_p <- read.csv('spear_synx1_p.csv', header=TRUE)
Shime1x_syn_spearman1 <- Heatmap(sx_syn, circlize::colorRamp2(c(-1, -0.5, 0, 0.5, 1),
c('#d7191c', '#fdae61',
'#FFFFFF', '#abd9e9',
'#2c7bb6')),
column_names_gp=grid::gpar(fontsize=20,
col=c(rep('#4daf4a', 8), rep('#984ea3',7))),
row_names_gp=grid::gpar(fontsize=20,
col=c(rep('#4daf4a', 8), rep('#984ea3',7))),
heatmap_legend_param=list(title="Spearman's rho",
direction='horizontal',
at = c(-1, -0.5, 0, 0.5, 1)),
cell_fun = function(j, i, x, y, w, h, fill){
if(sx_syn_p[i, j] < 0.05) {
grid.text('*', x, y)
}
})
sx_syn1_spear <- draw(Shime1x_syn_spearman1, heatmap_legend_side='top')
I thought the function inputs asterisks based on P < 0.05 from the spreadsheet, but the inputs does not seem to be placed correctly.
I managed to fix this by removing the first column of labels in the spreadsheet and re-running the code. I think that converting the data frame as a matrix would give further assurance per this example. The issue with my code was that the order of sx_syn
was not the same as sx_syn_p
.