[R] character variables in substitute()
Gabor Grothendieck
ggrothendieck at gmail.com
Tue Feb 2 18:15:10 CET 2010
Try this:
leg <- function(pNames, vparams) parse(text = paste(pNames, vparams,
sep = "=="))
plot(0, main = leg("Sigma", 3.2))
legend("topleft", legend = leg(c("alpha[beta]", "delta"), 1:2))
On Tue, Feb 2, 2010 at 11:44 AM, dkStevens <david.stevens at usu.edu> wrote:
>
> This is an interesting approach but it doesn't quite get what I want. The
> sample below is what I'm looking for where Eik's Title is compared with the
> text line within the plot. My text line was produced by the explicit
>
> text(0.6,1.2,expression(R *'= 13.35, ' *P[m] *'= 2.531, ' *alpha[r] *'=
> 0.007187'),pos=4)
>
> and the title was produced by
>
>
> expr<-bquote(italic(.(pNames[1]))==.(vparams[1])~","~.((pNames[2]))==.(vparams[2]))
> plot(1,1,main=expr)
>
> in which pNames is a vector of character c("R","P[m]",...) and vparams is a
> vector of characters representing the values with the # of digits limited to
> 4. What I'm struggling with is to get the pNames recognized as objects
> similar to those in the expression above, but using variables rather than
> explicitly.
>
> In addition, is is to all go into a function to build the expression for
> varying numbers of elements (e.g. maybe just R = or P[m] =, both, or even
> more. The return from this function would be the expr that goes into a
> text(... command or,as Eik used, a main= plot parameter.
>
> http://n4.nabble.com/file/n1460088/help.png
>
>
> --
> View this message in context: http://n4.nabble.com/character-variables-in-substitute-tp1459566p1460088.html
> Sent from the R help mailing list archive at Nabble.com.
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at 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.
>
More information about the R-help
mailing list