Re: [R] How add degree character in axis?

From: Marc Schwartz (via MN) <mschwartz_at_mn.rr.com>
Date: Sat 10 Jun 2006 - 06:00:17 EST

On Fri, 2006-06-09 at 11:01 +0000, fernando espindola wrote:
> Hi user R,
>
> I am try to put degree character in axis x, but don't make this. I have
> the next code:
>
> plot(mot[,5],
> time1,xlim=c(-45,-10),type="l",yaxt="n",ylab="",col=1,lwd=2,xlab="",xaxt="n")
>
> The range of value in axis-x is -45 to -10, this values represents the
> longitudes positions in space. I try to put 45S for real value (-45) in
> the axis-x, and for all elements . Anybody can give an advance in this
> problems.....
>
> Thank for all

In general, as Roger noted, see ?plotmath for adding mathematical annotation to R plots.

To do the degree symbol is relatively straightforward, but adding the "S" takes a bit of a trick:

# Create vector of x values
at <- seq(-45, -10, 5)

# Create a mock plot
plot(at, 1:8, xlim = range(at), xaxt = "n")

# Now create a set of plotmath expressions, one for 
# each value of 'at' using paste() and parse()
# The general format for the degrees symbol is x*degree
# However, to add the "S" we use the "~" to create 
# a right and left hand side for the expression and 
# place the "S" after it. The "~" will not print.
L <- parse(text = paste(at, "*degree ~ S", sep = ""))

# Now do the x axis
axis(1, at = at, labels = L)

HTH, Marc Schwartz



R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Sat Jun 10 06:11:39 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Sun 11 Jun 2006 - 05:34:59 EST.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.