1

I was wondering how I could have d in my R code below be used in legend?

Note that the reason I don't use d = c("dnorm", "dcauchy") is that in my actual code I need to use d[[1]](0) which doesn't work with quotations.

plot(1)
d = c(dnorm, dcauchy)
legend("topleft", legend = d) ## HERE how can I have the two terms:
                              ## dnorm and dcauchy in `d` appear as legend?
rnorouzian
  • 7,397
  • 5
  • 27
  • 72
  • `d = c("dnorm", "dcauchy")` ? – G5W Dec 04 '17 at 00:31
  • @rnorouzian you need to update/clarify your question then - because what GSW provided works fine to add the above text to a legend. – B Williams Dec 04 '17 at 00:41
  • @rnorouzian - i think you would be better served if you show your data and the figure code and exactly what you are trying to do. it appears like you are trying to assign values/labels instead of simply label the figure? – B Williams Dec 04 '17 at 00:46

1 Answers1

0

If you wish to use the same list as both the names and the functions you can do this.

d = c("dnorm", "dcauchy")     # works for printing strings

And when you want to use it as a function write

get(d[[1]])(0)
[1] 0.3989423
G5W
  • 36,531
  • 10
  • 47
  • 80