[R] How to superscript

Rolf Turner r.turner at auckland.ac.nz
Fri Feb 14 23:29:22 CET 2014


The given solution is the right one for the degree symbol, but does not 
answer the overall question of how to superscript, in particular how to 
superscript with nothing actually preceding the superscript.

In general "^" is used to obtain superscripts in plotmath (RTFM!) and if 
nothing comes before the superscript, replace the nothing by {}.

The following seems to work:

     plot(1:10,xlab="",ylab=expression(Temperature~{}^o*C))

The degree symbol however may be rendered better by "degree" than by "{}^o".

cheers,

Rolf Turner

On 15/02/14 06:20, arun wrote:
> Hi,
> Try:
> x <- 1985:1990
> set.seed(45)
> y <- sample(70:90,length(x),replace=TRUE)
> plot(x,y,xlab="Year",ylab=expression(Temperature~degree*C),main="April Average Temperature 1985-1990",type="p")
>
> A.K.
>
> I want to provide a label for my x,y plot as such: ylab="Temperature
> (^oC)", where the o is meant to be superscripted. This isn't working.
> I've googled it and looked at the user manual but I can't figure it out.
>   Can anyone explain the mechanism for superscripting something please?
>
> I've tried: plot(x,y, xlab(expression(Year)),
> ylab(expression(Temperature(~{o}~C))", main(expression(April Average
> Temperature 1961-2010)), type="p"),
> and I've tried some other things that I can't remember all of now.
> Very confused. It should be a simple thing to superscript something in a
>   heading!
>
> ______________________________________________
> 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