Seeking help to generate a similar heatmap as attached
0
0
Entering edit mode
2.1 years ago

I am trying to generate a heatmap as the following figure. I have already tried pheatmap and the code is as follows:

breaks_2 <- seq(min(0), max(2), by = 0.1)
pheatmap::pheatmap(mat = data,
                   cluster_cols = F,
                   cluster_rows = F,
                   scale = "column",border_color = "white",
                   color = inferno(20),
                   show_colnames     = TRUE,
                   show_rownames     = FALSE,
                   breaks = breaks_2)

But this does not seem to work. So far I am understanding I am mistaking with defining break or have to use another package than pheatmap. Any suggestion will be really helpful.

enter image description here

Heatmap R • 766 views
ADD COMMENT
0
Entering edit mode

It should be possible to get to something very close to that image with R, but what do you mean by "But this does not seem to work."? Do you get an error or is it just a bit different?

ADD REPLY
0
Entering edit mode

well, I get output, there is no error but I need a output like the file I attached. If you observe it, all values above 2 have daffodil color in inferno scale. So I set the breaks as seq(0,2) but my output is not like this. Now I am confused should I use another package other than pheatmap? or am I writing the code wrong?

ADD REPLY
0
Entering edit mode

Difficult to say what's not going as planned here. To find out, one would have to experiment with the data and settings. If you could also provide your data (or at least a representative sample), then we might figure something out. Otherwise, I see little chance.

ADD REPLY
0
Entering edit mode

Michael Dondrup My dataset looks like this: enter image description here If I run the following code : library(pheatmap)

library(RColorBrewer) 
library(viridis)
breaks_2 <- seq(min(0), max(2), by = 0.1)
pheatmap::pheatmap(mat = data_2,
                   cluster_cols = F,
                   cluster_rows = F,
                   scale = "column",border_color = "white",
                   color = rocket(20),
                   show_colnames     = TRUE,
                   show_rownames     = FALSE,
                   breaks = breaks_2)

my output looks like this: enter image description here but i need to create an output like this: enter image description here

ADD REPLY
0
Entering edit mode

There are of course multiple differences, but I am not considering you mean the difference in layout or geometry. But you definitely should try to turn on row clustering: cluster_rows = T, because rows in the example are definitely ordered in some way. It would be easiest if you also had the plotting code for your model output. Also, you might consider scaling the data before plotting.

Asides, I would like to question the motivation for replicating the image exactly, how does it make sense to aim at an exact replication if you don't have the exact same data?

ADD REPLY
0
Entering edit mode

But even the geometry might play a role in color perception, so before you compare the plots, make sure that they have about the same aspect ratio and similar number of rows in the heatmap.

ADD REPLY

Login before adding your answer.

Traffic: 2541 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6