0

I would like to set labels: it should be always "n" (for the number of observations) but with correct indices and values for each plot element.

For example, in the following simple example:

plot(1:4)
value<-c(10,20)
index<-c("a","b")
axis(3,at=c(2,3),labels=n?)

What should I do, so that first n has index "a" and value 10 and the second one index "b" and value 20?

Edit:

axis(3,at=c(2,3),
       labels=c(eval(substitute(expression(n==value), 
                                list(value=value[‌​1]))),
                eval(substitute(expression(n==value),
                                list(value=value[2])))))
Thomas
  • 43,637
  • 12
  • 109
  • 140
DatamineR
  • 10,428
  • 3
  • 25
  • 45
  • Hi, I would like to use n but with indices and values from another vectors, "index" and "value". For just values I would use: axis(3,at=c(2,3),labels=c(eval(substitute(expression(n==value),list(value=value[1]))),eval(substitute(expression(n==value),list(value=value[2]))))) – DatamineR Jul 04 '13 at 08:33

1 Answers1

2

It isn't entirely clear what you want to do. But most likely you will need to use ?expression and ?substitute to get this done. This should get you started:

plot(1:4)
value<-c(10,20)
index<-c("a","b")

lab <- rep(expression(paste("n"[index], "=", value, sep="")),2)

for (i in 1:length(lab)) {
  lab[i] <- eval(substitute(substitute(expr, list(value=value[i], index=index[i])), list(expr= as.call(lab[i]))))
}

axis(3,at=c(2,3),labels=lab)