Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

R, how can I make a heatmap out of a simple matrix? [duplicate]

Tags:

r

matrix

heatmap

Say I have a simple matrix A generated by

 A = matrix(c(1,2,3,4,5,6,7,8,9),nrow=3,ncol=3)

Now, my goal is to make a heatmap out of A, such that each number is replaced by a colour field. How to do that? I tried

heatmap(A)

but it produced three coloured stripes instead of 9 distinct fields.

like image 295
Joe Avatar asked Oct 23 '25 09:10

Joe


1 Answers

One of the possibilities that have not been described in the solutions referred to in the comments consists in using the pheatmap package:

library(pheatmap)
A <- matrix(c(1,2,3,4,5,6,7,8,9),nrow=3,ncol=3)
pheatmap(A, cluster_rows = FALSE, cluster_cols = FALSE)

which gives:

enter image description here

like image 55
RHertel Avatar answered Oct 26 '25 00:10

RHertel



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!