[R-sig-eco] labelling graph axes: sub/superscript

Gavin Simpson gavin.simpson at ucl.ac.uk
Tue Jul 28 14:19:18 CEST 2009

On Tue, 2009-07-28 at 12:09 +0100, Oliver, Rebecca wrote:
> Dear r list,
> I am having problems with superscripts and subscripts when labelling
> axes on graphs. I am trying to get the following label onto my y
> axis : Anet  (umol m-2 s-1). I am using the following code:
> >plot(SM,PN,pch=16,xlim=c(0,40),ylim=c(0,25),ylab=ytxt,xlab="soil
> moisture content (% vol.)",
> cex.lab=0.8,font.lab=1,bty="l",cex.axis=0.7,las=1)
> >ytxt=expression(""*A[net]*"  (umol  "*m^-2*" "*s^-1*")")
> Is it possible to get only Anet  in italics in this label?
> Additionally I find that the font.lab command does not work with axes
> containing sub/superscripts so you are forced to use all the default
> settings for you two axes to look the same. Does anyone know how I can
> correct this?

dat <- data.frame(x = rnorm(100), y = rnorm(100))
plot(y ~ x, data = dat,
     ylab = expression(italic(Anet) ~~ (mu*mol ~ m^{-2} ~ s^{-1}))) 

[the double ~~ is there to add a bit of extra spacing - the "t" looked
too close to the "(" with just one ~]

In these cases you are using plotmath, so reading ?plotmath is a must.
It contains a section on fonts and how to change them to different
families, but all font.lab does is switch between bold, plain italic
etc., which can all be done using things like italic() as documented
in ?plotmath.

Perhaps you can explain better with reproducible code what you want to
do or find annoying that is not covered in ?plotmath if the above
doesn't answer/help with the last part of your post?



 Dr. Gavin Simpson             [t] +44 (0)20 7679 0522
 ECRC, UCL Geography,          [f] +44 (0)20 7679 0565
 Pearson Building,             [e] gavin.simpsonATNOSPAMucl.ac.uk
 Gower Street, London          [w] http://www.ucl.ac.uk/~ucfagls/
 UK. WC1E 6BT.                 [w] http://www.freshwaters.org.uk

More information about the R-sig-ecology mailing list