This is a test version of Biostars. For the public version, visit https://www.biostars.org.
How do I put the color scales on heatmap.2?

Hello. I'm making a heatmap of my data using heatmap.2, but once the plot is done there is no color scale. Shouldn't it be done automatically? What function should I use to put it in the plot?

Also, I'm getting the mesage "Error in plot.new() : figure margins too large". I used the function margins =c() to lower the margins so that the image isn't cut, but I still get the mesage. Do I need to change something or is there no problem even if I get that mesage?

Thanks in advance.

heatmap.2 colorscale margins

Hi,

I guess that the color scale is not appearing due to the error that you're getting "Error in plot.new() : figure margins too large", so its being cut. This is my guess since I just searched for that function and it seems that gives a color scale (see the link).

Which are the dimensions (rows x cols) of your matrix? (that you're providing to the function)

António

I just tried on RStudio (v.2021.09.0 Build 351), with R version 4.1.2, gplots version 3.1.1, on Ubuntu 20.04.3 LTS, and it worked fine.

The dummy example that I used:

# Create fake matrix: 50 x 4
set.seed(1024)
m <- matrix(data = sample(100:1000, 200), ncol = 4)
row.names(m) <- paste0("row_", 1:nrow(m))
colnames(m) <- paste0("col_", 1:ncol(m))

# Import package 
library("gplots")

# Plotting heatmap
heatmap.2(m)

# Save heatmap
pdf("Desktop/heatmap.pdf", height=12) # you may adjust height
heatmap.2(m)
dev.off()

Perhaps try to avoid giving the margins option/function first to see if it works.

I guess that this also depends on how long are your label row names and col names.

I hope this helps,

António

are you using rstudio while plotting this?

One reason could be plot window (panel) is not big. Just drag the borders of plotting window to make it bigger.

0 answers

No answers yet.

Log in to answer this question.