Hi:
I played around with this earlier, but had only limited success. This is
what I
got; perhaps others can embellish this with more efficient (and correct)
code.
I couldn't get more than one expression in a line without overplotting.
Here's
an example:
plot(c(0, 1), c(0, 1))
text(0.5, 0.5, expression(R == 13.34859, P[m] == 2.53071))
# This makes sense, of course, because each expression is centered at
# the same point.
# You can put the text() statements along a row (pardon the crudity,
# and yes, there are no commas; it just makes the expressions more
# complicated):
plot(c(0, 1), c(0, 1))
text(0, 0.5, expression(R == 13.34859), adj = 0)
text(0.28, 0.5, expression(P[m] == 2.53071), adj = 0)
text(0.55, 0.5, expression(k[a] == 4.06000), adj = 0)
text(0.75, 0.5, expression(alpha[r] == 0.00719), adj = 0)
# However, one expression per line worked out OK (except for the
# desired five digit accuracy in k[a]...)
plot(c(0, 1), c(0, 1))
text(0.1, 0.9, expression(R == 13.34859), adj = 0)
text(0.1, 0.8, expression(P[m] == 2.53071), adj = 0)
text(0.1, 0.7, expression(k[a] == 4.06000), adj = 0)
text(0.1, 0.6, expression(alpha[r] == 0.00719), adj = 0)
# Trying multiple expressions in a plot title is equally challenging...here,
# only the first is rendered:
plot(c(0, 1), c(0, 1),
main = expression(R == 13.34859, P[m] == 2.53071, k[a] == 4.06000,
alpha[r] == 0.00719))
# The best I could do was paste text strings, but that's less
# than what we were hoping for...
plot(c(0, 1), c(0, 1),
main = paste('R = 13.34859, ', 'P[m] = 2.53071, ', 'k[a] =
4.06000, ',
'alpha[r] = 0.00719'), cex.main = 0.8)
I went through the plotmath demo and example and tried to find some
previous posts, but came up empty. There has to be a better way...
HTH,
Dennis
On Mon, Feb 1, 2010 at 9:50 PM, dkStevens <david.stevens@usu.edu> wrote:
>
> In trying to create a plotmath expression for plot labeling, such as
>
> R = 6, beta = 15
>
> where I want beta to be the Greek beta and, possibly, R in italics (like
> one
> would get in an explicit expression. The reason for this is that I want to
> write a string builder function that takes vectors of variable names and
> their values and return a plotmath expression for labeling a plot. One
> approach I tried is
>
> pname = c("R","beta")
> params = c(6,15)
> substitute(p == v,list(p = pname[i],v = format(params[i],digits=4))
>
> but this just copies the character strings in pname into the expression.
> Can
> anyone help me do what I want? How would I manage passing the resulting
> string back to the calling routine? Any help will be much appreciated.
>
>
> --
> View this message in context:
>
http://n4.nabble.com/character-variables-in-substitute-tp1459566p1459566.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> R-help@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.
>
[[alternative HTML version deleted]]