Explore Courses Blog Tutorials Interview Questions
0 votes
in R Programming by (5.3k points)
edited by

I'm new to R but I've made numerous correlation plots with smaller data sets. However, when I try to plot a large dataset (2gb+), I can produce the plot just fine, but the legend doesn't show up. Any advice? or alternatives?


r.cor <- cor(r)

layout(matrix(c(1,1,1,1,1,1,1,1,2,2), 5, 2, byrow = TRUE))


cx <- rev(colorpanel(25,"yellow","black","blue"))

leg <- seq(min(r.cor,na.rm=T),max(r.cor,na.rm=T),length=10)

image(r.cor,main="Correlation plot Normal/Tumor data",axes=F,col=cx)

axis(1, at=seq(0,1,length=ncol(r.cor)), labels=dimnames(r.cor)[[2]], 


axis(2,at=seq(0,1,length=ncol(r.cor)), labels=dimnames(r.cor)[[2]],



Error in : figure margins too large

tmp <- round(leg,2)

axis(1,at=seq(0,1,length=length(leg)), labels=tmp,cex.axis=1)

1 Answer

0 votes
edited by

This error occurs in Rstudio when your "Plots" pane is too small to fit the plot.

Include the following line before the line causing the error:

par(mar = rep(2, 4))

then plot the second image


You need to adjust the size of the margins on the par() call to get this right.

 You may also need to increase the size of the actual device onto which you are plotting.

A final tip, save the par() defaults before changing them, so change your existing par() call to:

op <- par(oma=c(5,7,1,1))

then at the end of plotting do


You can also the image size, or decrease the resolution using:

 png(filename="myfile.png", res=150, width = 1000, height = 1000)

Learn R Programming with the help of this R Programming Course by Intellipaat.

Related questions

Browse Categories