user1125946
user1125946

Reputation:

How to stop graphical device window cutting off edges of plot()?

I have a mfrow=c(6,4) plot and a special situation where I want each plot to be mar=c(1,1,1,1). This makes it such that the x-axis and the xlab of the bottom 4 graphs get chopped off (even when exporting to .eps).

How do I stop R doing this? I've tried doing postscript("test.eps",height=N) where N is some real number that's larger than the default. This makes a lot of white space in the top and bottom of the .eps but the x-axis is still cut off.

So my question is; how do I get plot() to stop cutting off my x-axis and xlab given the constraint that I want the mfrow and mar described above? (I'm looking perhaps for some way to make the bottom of the device bigger such that the stuff I want isn't chopped off?).

Here's my plots:

postscript("test.eps")
y <- rnorm(100)
x <- rnorm(100)

par(mfrow=c(6,4),mar=c(1,1,1,1))

for(i in 1:((6*4)))
{
    if(i <= (6*4)-4)
    {
    plot(y,x,xlab="",xaxt="n")
    }
    if(i > (6*4)-4)
    {
    plot(y,x,xlab="HELLO")
    }
}
dev.off()

Upvotes: 6

Views: 16288

Answers (1)

Backlin
Backlin

Reputation: 14872

I suggest you add an outer margin (oma) to not clip the tick labels, and plot the axis-label with mtext to get it closer than the default position.

postscript("test.eps")
y <- rnorm(100)
x <- rnorm(100)

par(mfrow=c(6,4),mar=c(1,1,1,1), oma=c(3,1,0,0))

for(i in 1:((6*4)))
{
    if(i <= (6*4)-4)
    {
    plot(y,x,xlab="",xaxt="n")
    }
    if(i > (6*4)-4)
    {
    plot(y,x,xlab="")
    mtext("HELLO", 1, 2.5)
    }
}
dev.off()

enter image description here

Upvotes: 3

Related Questions