How to calculate cex.axis automatically so to fit to the maximal width possible (in R)? Let's say we created a plot, with labels:
plot(1, xlab = "text", ylab = "text times three") # text too small

In this plot there is still a lot of free region to enlarge the text.  We could do so by using cex.lab, like this:
par(cex.lab = 2)
plot(1, xlab = "text", ylab = "text times three")

Questions:


*

*Is there a way to know what is the largest cex.lab possible, without the text getting over the borders?

*Is it possible to do that separately for each component of the axis? (so to have a different fitting of cex.axis to the xlab vs the ylab) ?

 A: The following uses calls to par(), strheight() and strwidth() to fit within the borders of the plot area and the edges of the margin for the text.  They don't rescale together the same so this will give you a framework for redrawing your graph if you change the overall dimensions.  If you want something different this will be good to build on.  If you want to take up more of the margin area you need to look at parameters for the number of lines in a margin, lineheight, etc.  par() is what you need to do what you want but your question is vague.  This will do an interpretation of it.
sx <- 'my x-label'
sy <- 'my y-label'
plot(rnorm(4), ann = FALSE)
#work out string width max
maxcexXh <- par('pin')[1]/strwidth(sx,'inches')
maxcexYh <- par('pin')[2]/strwidth(sy,'inches')
#work out string height max
maxcexXv <- (par('mai')[1]/par('mar')[1])/strheight(sx,'inches')
maxcexYv <- (par('mai')[2]/par('mar')[2])/strheight(sy,'inches')
maxcexX <- min(maxcexXh, maxcexXv)
maxcexY <- min(maxcexYh, maxcexYv)
title(xlab = sx, cex.lab = maxcexX)
title(ylab = sy, cex.lab = maxcexY)

This likely is staying within the height of the string on your computer.  If you made the text much longer it would stay within the width.
My guess is that after you've done this you'll realize it's not a good idea.
A: I can't think of an answer to Q1, but Q2 can be done via separate calls to title(). Here's an example
x <- 1:10
y <- runif(10)
plot(y ~ x, ann = FALSE)
title(ylab = "my Y axis label", cex.lab = 2)
title(xlab = "my X axis label", cex.lab = 3)

But I don't see the value in doing this, as won't the user be drawn to the fact that the labels are drawn to a different size? If they are (I would be) then the user will not be focussing on what the plot is designed to show.
