hi I´m trying to display the numbers of a df on a HEATMAP
I have this df
> matrinrmatr
ce n1 n2 n3 ca
sn 6.47 1.89 0.52 NA NA
inn 6.47 3.94 NA NA NA
pn 6.93 NA NA NA NA
bn 6.40 6.63 5.08 5.56 2.73
cn 7.67 2.13 2.03 5.70 NA
vn 7.29 3.37 2.76 3.74 2.18
cin 5.57 3.61 2.51 3.72 2.18
and i try to make a heatmap using the following script
hmmatrinr <- Heatmap(matrinrmatr,
row_title="Grupos",
column_title="camadas",
col=colheatp,
cluster_rows=FALSE,
cluster_columns=FALSE,
show_column_dend=FALSE,
width=unit(6, "cm"),
height=unit(9, "cm"),
heatmap_legend_param=list(
title="Score",
at=c(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12),
legend_height=unit(8, "cm"),
grid_width=unit(0.5, "cm")
),
layer_fun <- function(j, i, x, y, width, height, fill) {
grid.text
(sprintf("%s",
pindex(matrinrmatr, i, j),
x=x, y=y,
gp=gpar(fontsize=10, col="grey")))
}
)
I had this without the layer_fun part a heatmap without the numbers on the cells https://i.stack.imgur.com/0AMoV.png
the problem is with layer_fun part
it gave me
Error in sprintf("%s", pindex(matrinrmatr, i, j), x = x, y = y, gp = gpar(fontsize = 10, :
arguments cannot be recycled to the same length
I tried to use
layer_fun <- function(j, i, x, y, width, height, fill) {
grid.text
(sprintf(
"%f",
pindex(matrinrmatr, i, j), x=x, y=y))
}
and the result was
Warning message:
In sprintf("%f", pindex(matrinrmatr, i, j), x = x, y = y) :
2 arguments not used by format '%f
Also tried
layer_fun <- function(j, i, x, y, width, height, fill) {
grid.text
(sprintf("%s",
pindex(matrinrmatr, i, j), x=x, y=y))
}
and gave me
Warning message:
In sprintf("%s", pindex(matrinrmatr, i, j), x = x, y = y) :
2 arguments not used by format '%s'
without the numbers
I will be grateful if someone can help me. Thanks