Giuseppe
Giuseppe

Reputation: 816

mtext: smaller labels description when layout is used

Using mtext for the label description does something different than using xlab. How can I make the mtext labels be always the same size as it would be when using xlab (without defining always the cex argument). In the minimal example below cex=cex.lab=1 for both figures. However the size is different.

layout(matrix(c(1,1,2,2), ncol=1))
op<-par(mar=c(4,4,2,1))
plot(1:10, xlab="", ylab="", main="This is my title")
mtext("this is the x-axis", side=1, line=2.75, cex=1)
mtext("this is the y-axis", side=2, line=2.5, cex=1)
plot(1:10,  xlab="this is smaller", ylab="this is smaller", main="This is my title", cex.lab=1)
par(op)

enter image description here

Upvotes: 2

Views: 6176

Answers (2)

ThanasisN
ThanasisN

Reputation: 103

Just found out that you can use title instead of mtext.

title(ylab = "this is the y-axis", line = 3.5, . . . )

I had the same problem with font scaling, this way it should work without having to know the scaling factor in advance.

Upvotes: 0

IRTFM
IRTFM

Reputation: 263342

When layout is used, the meaning of cex=1 in plot is different, but I would not have expected that difference to extend to mtext since its activities are outside the individual plotting regions. You can reverse the default reduction in "effective"-cex inside plot by inverting the expected factor of 2/3:

layout(matrix(c(1,1,2,2), ncol=1))
op<-par(mar=c(4,4,2,1))
plot(1:10, xlab="", ylab="", main="This is my title")
mtext("this is the x-axis", side=1, line=2.75, cex=1)
mtext("this is the y-axis", side=2, line=2.5, cex=1)
plot(1:10,  xlab="this is _not_ smaller", 
            ylab="this is _not_ smaller, either", 
            main="This is my title", 
            cex.lab=3/2)
par(op)

Further reading:

 ?par  # scroll down to mfcol, mfrow

Upvotes: 3

Related Questions