Posted By: Anonymous
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?
library(gplots) r.cor <- cor(r) layout(matrix(c(1,1,1,1,1,1,1,1,2,2), 5, 2, byrow = TRUE)) par(oma=c(5,7,1,1)) 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)[], cex.axis=0.9,las=2) axis(2,at=seq(0,1,length=ncol(r.cor)), labels=dimnames(r.cor)[], cex.axis=0.9,las=2) image(as.matrix(leg),col=cx,axes=T)
plot.new(): figure margins too large
tmp <- round(leg,2) axis(1,at=seq(0,1,length=length(leg)), labels=tmp,cex.axis=1)
The problem is that the small figure region 2 created by your
layout() call is not sufficiently large enough to contain just the default margins, let alone a plot.
More generally, you get this error if the size of the plotting region on the device is not large enough to actually do any plotting. For the OP’s case the issue was having too small a plotting device to contain all the subplots and their margins and leave a large enough plotting region to draw in.
RStudio users can encounter this error if the Plot tab is too small to leave enough room to contain the margins, plotting region etc. This is because the physical size of that pane is the size of the graphics device. These are not independent issues; the plot pane in RStudio is just another plotting device, like
reducing the size of the margins; this might help especially if you are trying, as in the case of the OP, to draw several plots on the same device.
increasing the physical dimensions of the device, either in the call to the device (e.g.
pdf(), etc) or by resizing the window / pane containing the device
reducing the size of text on the plot as that can control the size of margins etc.
Reduce the size of the margins
Before the line causing the problem try:
par(mar = rep(2, 4))
then plot the second image
You’ll need to play around with the size of the margins on the
par() call I show to get this right.
Increase the size of the device
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