Question: Error in : figure margins too large
gravatar for mictadlo
11 days ago by
mictadlo0 wrote:

Hi, I got Error in : figure margins too large with the below code:

> logCPM <- cpm(y, prior.count=2, log=TRUE)
> head(y$genes)
   gene_name                                    gene_description
3  sp0000003                                                <NA>
4  sp0000004                                                <NA>
5  sp0000005                                          PUA domain
6  sp0000006 Sugar efflux transporter for intercellular exchange
8  sp0000008                                                <NA>
12 sp0000012                       Ankyrin repeats (many copies)
> y$samples$group
 [1] Root_tip.1.5 Root_tip.1.5 Root_tip.1.5 Root_tip.1.5 Leaves.1.5   Leaves.1.5  
 [7] Leaves.1.5   Leaves.1.5   Root_tip.2   Root_tip.2   Root_tip.2   Root_tip.2  
[13] Leaves.2     Leaves.2     Leaves.2     Leaves.2     Root_tip.3   Root_tip.3  
[19] Root_tip.3   Root_tip.3   Leaves.3     Leaves.3     Leaves.3     Leaves.3    
Levels: Leaves.1.5 Leaves.2 Leaves.3 Root_tip.1.5 Root_tip.2 Root_tip.3
> rownames(logCPM) <- y$genes$genes
> colnames(logCPM) <- paste(y$samples$group, 1:2, sep="-")
> o <- order(tr$table$PValue)
> logCPM <- logCPM[o[1:30],]
> logCPM <- t(scale(t(logCPM)))
> library(gplots)

Attaching package: ‘gplots’

The following object is masked from ‘package:stats’:


> col.pan <- colorpanel(100, "blue", "white", "red")
> heatmap.2(logCPM, col=col.pan, Rowv=TRUE, scale="none",
+           trace="none", dendrogram="both", cexRow=1, cexCol=1.4,"none",
+           margin=c(10,9), lhei=c(2,10), lwid=c(2,6))
Error in : figure margins too large

What did I miss?

Thank you in advance.

ADD COMMENTlink modified 11 days ago by Gordon Smyth32k • written 11 days ago by mictadlo0
gravatar for Gordon Smyth
11 days ago by
Gordon Smyth32k
Walter and Eliza Hall Institute of Medical Research, Melbourne, Australia
Gordon Smyth32k wrote:

I can see that you are copying code verbatim from the edgeR case study workflow published on F1000Research: . It would be a good idea to say this in your question so that people know what the question is about.

The obvious problem is that the case study in F1000Research had only 6 samples whereas your data has 23 samples. So obviously your heatmap will be wider than the one in the published workflow. So you won't be able to leave as much space for margins.

The code in the workflow wasn't intended to be copied verbatim into new analyses. It is just as example of how R and Bioconductor can be used. For normal routine use of heatmap.2 you don't need to set the detailed graphical parameters such as margin, lhei or lwid. You can just omit them.

Can I suggest that you try:

logCPM <- cpm(y, log=TRUE, prior.count=3)
logCPM <- logCPM[o[1:30],]
ADD COMMENTlink modified 11 days ago • written 11 days ago by Gordon Smyth32k
gravatar for James W. MacDonald
11 days ago by
United States
James W. MacDonald44k wrote:

Two things. First, this question has nothing to do with edgeR, nor ggplot2, so you shouldn't be tagging with those tags. The tags actually have a purpose, as some maintainers just follow certain tags for their own packages, and you stand a chance of them missing your post if you just use random tags.

Second, while you might be using edgeR for your analysis, the question you have is about heatmap.2, which is a CRAN package, not Bioconductor. If you want to ask questions about CRAN packages (and about using R in general), you should A.) try to figure it out yourself by googling the error, etc, and then B.) posting to R-help ( But do note that people on R-help can be less forgiving of those who seem not to have tried to figure things out themselves first, so do A first.

If you want to generate heatmaps using a Bioconductor package, you might look at ComplexHeatmap, which is a bit nicer IMO than heatmap.2, which is pretty old school.

ADD COMMENTlink written 11 days ago by James W. MacDonald44k

Thank you for pointing out that it is a CRAN package.

ADD REPLYlink written 11 days ago by mictadlo0
gravatar for Peter Langfelder
11 days ago by
United States
Peter Langfelder1.3k wrote:

To the OP's question, the error usually means the plotting window, or the current plot area of  a plot window, is too small to accommodate the requested plot margins. The fix may be as easy as enlarging the plot window but you may have to modify the  the margins and lhei, lwid arguments. See ?heatmap.2 for details.

ADD COMMENTlink written 11 days ago by Peter Langfelder1.3k
Please log in to add an answer.


Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.2.0
Traffic: 181 users visited in the last hour