[R] Impact of cex changing as a function of mfrow

Fisher Dennis fisher at plessthan.com
Mon Sep 3 01:53:12 CEST 2012


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:

> R 2.15.1
> OS X (MLion)
> 
> Colleagues,
> 
> I am aware that changes in mfrow / mfcol in par() affect cex (from help: In a layout with exactly two rows and columns the base value of ‘"cex"’ is reduced by a factor of 0.83: if there are three or more of either rows or columns, the reduction factor is 0.66).
> 
> I generate a multipage PDF in which mfrow varies such that cex is impacted.  This affect mtext in the outer margin.  Sample code is pasted at the bottom of this email.  The impact is most obvious if one examines the text at the bottom of each page as one moves page-to-page.
> 
> Does anyone have a suggestion for how to overcome this (other than using brute force).
> 
> 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
> 
> # In a layout with exactly two rows and columns the base value of ‘"cex"’ is reduced by a factor of 0.83: if 
> # there are three or more of either rows or columns, the reduction factor is 0.66.
> 
> 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)
> 	}
> pdf("TestCEX.pdf", 8, 6)
> par(mfrow=c(1,1), omi=c(1,1,1,1))
> plot(1)
> mtext(outer=T, side=1, line=0, cex=1, "line 0")
> mtext(outer=T, side=1, line=FINDCEX(), cex=1, "line FINDCEX")
> mtext(outer=T, side=3, line=0, cex=1, "line 0")
> mtext(outer=T, side=3, line=1, cex=1, "line 1")
> mtext(outer=T, side=2, line=0, cex=1, "line 0")
> mtext(outer=T, side=2, line=FINDCEX(), cex=1, "line FINDCEX")
> mtext(outer=T, side=4, line=0, cex=1, "line 0")
> mtext(outer=T, side=4, line=1, cex=1, "line 1")
> 
> 
> par(mfrow=c(1,2), omi=c(1,1,1,1))
> plot(1)
> mtext(outer=T, side=1, line=0, cex=1, "line 0")
> mtext(outer=T, side=1, line=FINDCEX(), cex=1, "line FINDCEX")
> mtext(outer=T, side=3, line=0, cex=1, "line 0")
> mtext(outer=T, side=3, line=1, cex=1, "line 1")
> mtext(outer=T, side=2, line=0, cex=1, "line 0")
> mtext(outer=T, side=2, line=FINDCEX(), cex=1, "line FINDCEX")
> mtext(outer=T, side=4, line=0, cex=1, "line 0")
> mtext(outer=T, side=4, line=1, cex=1, "line 1")
> 
> par(mfrow=c(2,2), omi=c(1,1,1,1))
> plot(1)
> mtext(outer=T, side=1, line=0, cex=1, "line 0")
> mtext(outer=T, side=1, line=FINDCEX(), cex=1, "line FINDCEX")
> mtext(outer=T, side=3, line=0, cex=1, "line 0")
> mtext(outer=T, side=3, line=1, cex=1, "line 1")
> mtext(outer=T, side=2, line=0, cex=1, "line 0")
> mtext(outer=T, side=2, line=FINDCEX(), cex=1, "line FINDCEX")
> mtext(outer=T, side=4, line=0, cex=1, "line 0")
> mtext(outer=T, side=4, line=1, cex=1, "line 1")
> 
> par(mfrow=c(3,3), omi=c(1,1,1,1))
> plot(1)
> mtext(outer=T, side=1, line=0, cex=1, "line 0")
> mtext(outer=T, side=1, line=FINDCEX(), cex=1, "line FINDCEX")
> mtext(outer=T, side=3, line=0, cex=1, "line 0")
> mtext(outer=T, side=3, line=1, cex=1, "line 1")
> mtext(outer=T, side=2, line=0, cex=1, "line 0")
> mtext(outer=T, side=2, line=FINDCEX(), cex=1, "line FINDCEX")
> mtext(outer=T, side=4, line=0, cex=1, "line 0")
> mtext(outer=T, side=4, line=1, cex=1, "line 1")
> 
> graphics.off()
> system("open TestCEX.pdf")
> 




More information about the R-help mailing list