[R] Special characters: plus/minus - a method that works

Martin Maechler maechler at stat.math.ethz.ch
Tue Mar 21 11:22:16 CET 2006

>>>>> "Peter" == Peter Alspach <PAlspach at hortresearch.co.nz>
>>>>>     on Tue, 21 Mar 2006 14:35:43 +1200 writes:

    Peter> Gabor Grothendieck wrote:

    >> Another way that works on my Windows XP system is to use "\261" .

    Peter> Please note Windows escape codes are not portable thus not recommended as Martin Maechler pointed out in a response to a suggestion of mine:

    Peter> On Tue, 14 Jun 2005, Martin Maechler wrote:

    >>>>>>> "Peter" == Peter Alspach <PAlspach at hortresearch.co.nz>
    >>>>>>> on Tue, 14 Jun 2005 14:11:47 +1200 writes:
    Peter> Ben
    Peter> Others have pointed out plotmath. However, for some
    Peter> superscripts (including 2) it may be easier to use
    Peter> the appropriate escape sequence (at in Windows):
    Peter> ylab = 'BA (m\262/ha)'
    >> but please refrain from doing that way.
    >> You should write R code that is portable, and ``plotmath''
    >> has been designed to be portable. Windows escape codes are not,
    >> and may not even work in future (or current?) versions of
    >> Windows with `unusual' locale settings {fonts, etc}.

    Peter> Peter Alspach

Indeed, thank you, Peter.

For the present case, 
if you really want something better than the ASCII "+/-" that
Duncan recommended (and I agree),
you can do what I had recommended above:  

use 'plotmath' --> ?plotmath
and see that

the    %+-%   symbol works -- platform independently! -- 

  plot(1, main = expression(3 %+-% 0.1))

or a bit more realistically:

   m <- pi
  sd <- 1/7
  plot(1, main = substitute(mu %+-% sig, list(mu = m, sig = sd)))
## or
  plot(1, main = substitute(mu %+-% sig, 
                            list(mu= round(m,3), sig= round(sd,3))))

Martin Maechler, ETH

More information about the R-help mailing list