[R] mtext text size (cex) doesn't match plot

George Locke george.locke.physics at gmail.com
Wed May 11 23:55:39 CEST 2011


Hi,

I am using mtext instead of the ylab argument in some plots because i
want to move it away from the numbers in the axis.  However, the text
in the X axis,

for example:
    par(mar=c(5, 5.5, 4, 2));
    plot(data, main="plot name", xlab= 'X axis', ylab="",
         font=2, cex.lab=1.5, font.lab=2, cex.main=1.8);
    mtext('Y axis', side=2, cex=1.5, line=4, font=2);

This works fine, but if I then set

    par(mfrow=c(3,2));

the text produced by mtext becomes much larger than the text "X axis"
produced by plot, despite their having identical cex specifications.
In this case, the words "Y axis" become much larger than "plot name".
Note that without par(mfrow) the size of "X axis" and "Y axis" match
iff their cex(.lab) arguments match.

How can I make mtext produce text that exactly matches the xlab?  In
my limited experience fiddling around with this problem, the size of
the mtext does not depend on par(mfrow), whereas the size of the xlab
does, so if there were a formula that relates the actual size of text,
cex argument, and par(mfrow), then I could use that to attenuate the
cex argument of mtext.  Any solution will do, so long as it maintains
the relative sizes of the plot and the three text fields (main, x axis
label, y axis label).


example code to demonstrate the problem is below.

Thanks!

    data = c(1:10);
    par(mfrow=c(3,2));

    par(mar=c(5, 5.5, 4, 2));
    plot(data, main="plot name", xlab= 'X axis', ylab="",
         font=2, cex.lab=1.5, font.lab=2, cex.main=1.8);
    mtext('Y axis', side=2, cex=1.5, line=4, font=2);

    par(mar=c(5, 5.5, 4, 2));
    plot(data, main="plot name", xlab= 'X axis', ylab="",
         font=2, cex.lab=1.5, font.lab=2, cex.main=1.8);
    mtext('Y axis', side=2, cex=1.5, line=4, font=2);

    par(mar=c(5, 5.5, 4, 2));
    plot(data, main="plot name", xlab= 'X axis', ylab="",
         font=2, cex.lab=1.5, font.lab=2, cex.main=1.8);
    mtext('Y axis', side=2, cex=1.5, line=4, font=2);

    par(mar=c(5, 5.5, 4, 2));
    plot(data, main="plot name", xlab= 'X axis', ylab="",
         font=2, cex.lab=1.5, font.lab=2, cex.main=1.8);
    mtext('Y axis', side=2, cex=1.5, line=4, font=2);

    par(mar=c(5, 5.5, 4, 2));
    plot(data, main="plot name", xlab= 'X axis', ylab="",
         font=2, cex.lab=1.5, font.lab=2, cex.main=1.8);
    mtext('Y axis', side=2, cex=1.5, line=4, font=2);

    par(mar=c(5, 5.5, 4, 2));
    plot(data, main="plot name", xlab= 'X axis', ylab="",
         font=2, cex.lab=1.5, font.lab=2, cex.main=1.8);
    mtext('Y axis', side=2, cex=1.5, line=4, font=2);



More information about the R-help mailing list