Add mean values of the columns of the Heatmaply heatmap as an anotation near it

124 views Asked by At

How can I add the mean values of the columns of the Heatmaply heatmap as an anotation near it?

Currently, as a not ideal approach, I run this and got the below figure:

x<- mtcars
mmeans <-round(rowMeans(mtcars), digits = 2 )
rownames(x) <- paste0(rownames(x)," = ", mmeans)
heatmaply(x, Rowv=F, Colv=F)

enter image description here

However, this is not ideal. I want to have the mean values as another independent column added to heat map in which I can show the values as well.

Also, I need the column label at top, which I asked here:

I am planning to use this heatmap in a shiny app.

Thanks

1

There are 1 answers

0
emcee elegans On

You can use "cbind()" to add the means as another column to your matrix. Then use the updated matrix as the heatmaply input.

x <- mtcars
rownames(x) <- paste0(rownames(x),"=", mmeans)
mmeans <- round(rowMeans(mtcars), digits = 2 )
x_new <- cbind(x, mmeans) 
heatmaply(x_new, Rowv=F, Colv=F, fontsize_row=5)

Hope this helps and answers your question, albeit late.