Skip to content
Prev 304713 / 398506 Next

Impact of cex changing as a function of mfrow

Duncan

I are getting closer to an understanding.  
	1.  "index" is not relevant to the discussion.  i am focused solely on margin text
	2.  the size pf the margin text does not change between pages
	3.  however, the location does change, moreso on the top / right than on the left / bottom.

I rewrote the code to better illustrate the problem:
###########################
FINDCEX <- function()
        {
        CORRECT <- 1
        MFROW           <- par()$mfrow
        MFCOL           <- par()$mfcol
        TEST            <- all(MFROW == MFCOL)
        if (TEST && MFROW == c(2,2))                            CORRECT <- 1 / 0.83
        if (TEST && (MFROW[1] >= 3 | MFROW[2] >= 3))    CORRECT <- 1 / 0.66
        if (!TEST)      cat("MFROW does not equal MFCOL\n")
        cat(MFROW, CORRECT, "\n")
        return(CORRECT)
        }
DRAW    <- function(N)
        {
        for (i in 1:N)
                {
                plot(1, bty="n")
                box(which="inner")
                }
        for (SIDE in 1:2)
                {
                mtext(outer=T, side=SIDE, line=0, cex=1, "line 0")
                mtext(outer=T, side=SIDE, line=FINDCEX(), cex=1, "line FINDCEX")
                mtext(outer=T, side=SIDE, line=-FINDCEX(), cex=1, "line FINDCEX")
                }
        for (SIDE in 3:4)
                {
                mtext(outer=T, side=SIDE, line=0, cex=1, "line 0")
                mtext(outer=T, side=SIDE, line=1, cex=1, "line 1")
                }
        }
pdf("TestCEX.pdf", 10, 8)
par(mfrow=c(1,1), omi=c(1,1,1,1))
DRAW(1)
par(mfrow=c(2,2), omi=c(1,1,1,1))
DRAW(4)
par(mfrow=c(3,3), omi=c(1,1,1,1))
DRAW(9)
graphics.off()
system("open TestCEX.pdf")

system("open TestCEX.pdf")	## in Windows, "start" instead of "open"
################

If you execute this code, you will see:
1.  the box at the outer border is identical on all pages (as expected)
2.  the margin side on the left side superimposes between pages
3.  on the bottom, margin text is spaced the same on each page (unlike at the top).  However, the vertical position differs between pages (most obvious on comparing pages 1 and 3).  

I could correct the vertical positioning by brute force, i.e., adding a constant to each mtext command (applying a different value based on the value of mfrow) -- It turn out that a correction of 0.2 (for mfrow=c(2,2) and 0.4 (for mfrow=c(2,2) aligns everything properly.  .  However, this is not elegant.  The correction factor took care of line-to-line spacing but not vertical position.

Dennis



Dennis Fisher MD
P < (The "P Less Than" Company)
Phone: 1-866-PLessThan (1-866-753-7784)
Fax: 1-866-PLessThan (1-866-753-7784)
www.PLessThan.com
On Sep 2, 2012, at 10:40 AM, Dennis Fisher wrote: