[R] Font size in plots (I do NOT understand par help)
Dan Davison
davison at stats.ox.ac.uk
Wed Aug 6 17:10:53 CEST 2008
On Wed, Aug 06, 2008 at 03:37:48PM +0100, Stephane Bourgeois wrote:
> Hi,
>
>
>
> I do not get how par works, help please.
>
>
>
> Let's say I have a simple plot: plot(1:10)
>
>
>
> I want to change the font size for the x axis... how do I do that?
OK, so firstly go to the help page for par by typing
?par
I'm not saying you should read the whole thing right now. There's
quite a lot of options. But you want to change something to do with
axes, so search for the word 'axis'. The 3rd hit I get shows the
following lines.
'cex.axis' The magnification to be used for axis annotation
relative to the current setting of 'cex'.
'cex.lab' The magnification to be used for x and y labels relative
to the current setting of 'cex'.
Note that one of those refers to the axis annotation (i.e the numbers
along the axis), whereas the other refers to the axis labels. Now
there's two ways to proceed. First, note that par() is a
function. When you call the function, it changes the values of the
graphics parameters you specify. So say you want to make the axis
labels font twice as big. The first method would be
par(cex.lab=2)
plot(1:10)
An alternative method is as follows:
plot(1:10, cex.lab=2)
If you don't know why that works, look at the help page for plot by
typing ?plot, and read the stuff about the three dots (...)
If you go for the first method, one useful trick is to save the
previous values, so you can restore them. You would do that like this:
old.par.settings <- par(cex.lab=2)
plot(1:10)
## now restore them
par(old.par.settings)
That works because the function par() happens to spit out the old
values as its return value, although its effect is to change them.
To be fair, you actually asked how to change the font size on the
x-axis, whereas the above changes it on both axes. AFAIK there's no
par() options that do exactly that, so the way I'd do it would be to
first plot without any axis labels, and subsequently add the x- and y-
labels independently using the title() function, and passing extra
'cex.lab=' arguments in the same way as the second method above:
> plot(1:10, xlab="", ylab="")
> title(xlab="xlab title", cex.lab=3)
> title(ylab="ylab title", cex.lab=.5)
Dan
>
>
>
> Thank you,
>
>
>
> Stephane
>
>
>
>
> --
> The Wellcome Trust Sanger Institute is operated by Genome Research
>
> Limited, a charity registered in England with number 1021457 and a
> compa
> ny registered in England with number 2742969, whose registered
> office is 2
> 15 Euston Road, London, NW1 2BE.
>
>
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
More information about the R-help
mailing list