[R] Strange axis labels?
Uwe Ligges
ligges at statistik.uni-dortmund.de
Mon Dec 23 19:30:03 CET 2002
"Anon." wrote:
>
> Moi!
>
> I'm trying to add a rather long label to a y-axis, and it's so long that
> it won't fit into one line. However, things get strange when I try and
> split it over 2 lines. The problem seems to be the plus/minus symbol,
> which means I have to use expression(). I'm using R1.6.1 on Windoze
> 2000.
I think it's not the symbol, it's the not very appropriate use of the
help page ?plotmath.
[BTW: I guess your OS is called Windows 2000.]
> As an example:
>
> thing1 <- expression(paste("log odds of survival probability ( " %+-%
> "95% C.I.)", sep=" ")
> thing2 <- expression(paste("log odds of survival probability \n( " %+-%
> "95% C.I.)"))
>
> plot(c(1,2), c(1,2), ylab=thing1)
> par(mar =c(2.1, 6.1, 2.1, 2.1)); plot(c(1,2), c(1,2), ylab=thing2)
>
> The first plot has the label on one line, with only a single space
> between the bracket and the +/-. Tbis is what I want, but I wonder why
> paste has a sep=, if it doesn't do anything (I assume I've missed
> something here).
You gave paste() exactly one argument (additionally to "sep"). So
between which arguments do you expect the spaces? So in your example,
paste() is superfluously. BTW, ?plotmath doesn't say anything about
"sep":
"paste(x, y, z) --- juxtapose x, y, and z"
To put extra spaces in, you might want to use "~~", ?plotmath says:
"x ~~ y --- put extra space between x and y",
or phantom(...), ?plotmath:
"x + phantom(0) + y --- leave gap for "0", but don't draw it"
Example:
thing1 <- expression("log odds of survival probability (" *
phantom(0) %+-% "95% C.I.)")
plot(c(1,2), c(1,2), ylab=thing1)
> The second plot has the label on 2 lines (you need the par() to get it
> all in!), but the open bracket, "(", lines up with the start of the
> first lines, and there is then a large gap, and the string continues
> with the plus/minus below and to the right of the final part of the
> first line. Not what I expected at all. Can anyone explain what's
> going on, and how to remove this large space?
The internal algorithms are calculating the spaces needed to plot the
whole expression into one rectangle . And one of the spaces (that one to
the left) persists after your forced the linebreak; more precisely, all
spaces are still there (including those below the first part of your
formula, and above the second part, respectively). "\n" within
expressions is not documented to work for mathematical annotation.
So don't specify it as "ylab" in your call to plot(), but as two calls
to mtext(), one call for each line. See ?mtext for details.
Example:
plot(c(1,2), c(1,2), ylab="")
mtext("log odds of survival probability", 2, line = 3)
mtext(expression("(" %+-% "95% C.I.)"), 2, line = 2)
Uwe Ligges
More information about the R-help
mailing list