简体   繁体   English

函数名称在R中以图例形式评估为文本?

[英]Function names evaluated as text in legend in R?

I was wondering how I could have d in my R code below be used in legend ? 我想知道如何在下面的R代码中将d用于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. 请注意,我不使用d = c("dnorm", "dcauchy")是,在我的实际代码中,我需要使用d[[1]](0) ,它不能用引号引起来。

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?

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM