[R] Building a plotmath string in a function

dkStevens david.stevens at usu.edu
Mon Feb 1 18:43:05 CET 2010

I apologize if this has been asked before but I've look for a long time with
no success.  My problem is that I want to annotate a plot with an expression
that combines parameter names with fitted values for from 1 to n parameters
depending on the problem - something like

R = 16.1, P[m] = 4.51, k[a] = 7.23, alpha[r] = .01 ...

with the [] values as subscripts. I thought that because the number and
names of the parameters would vary, doing this in a function would be best.
I've attempted a variety of as.expressions, substitutes, evals in a loop
that loops through the list of parameters sent to the function but am
getting nowhere.  Could someone point me to some references beyond the
standard documentation that might help.  Here's my latest attempt:

BuildParString = function(params) {

  nPar = length(params)  # params is a vector of numerical values
    s = NULL
  if(nPar < 1) {

  pNames = c("R","P[m]","k[a]","alpha[r]","beta[r]","phi")
  vparams = format(params,digits=3)

  s = as.expression(substitute(pp==vv,list(vv=vparams[1],pp=pNames[1])))
  for(i in 2:nPar) {
  s =

#  the result is 
expression("R" == "13.34859", "P[m]" == " 2.53071", "k[a]" == " 4.06000", 
    "alpha[r]" == " 0.00719")

which in spirit is what I want but won't plot properly using text (...). Any
help would be appreciated.
View this message in context: http://n4.nabble.com/Building-a-plotmath-string-in-a-function-tp1459048p1459048.html
Sent from the R help mailing list archive at Nabble.com.

More information about the R-help mailing list