[R] How add degree character in axis?

Marc Schwartz (via MN) mschwartz at mn.rr.com
Fri Jun 9 22:00:17 CEST 2006

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 45°S 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)


Marc Schwartz

More information about the R-help mailing list