如何结合do.call()plot()和expression() [英] How to combine do.call() plot() and expression()

查看:83
本文介绍了如何结合do.call()plot()和expression()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我尝试将expressiondo.callplot结合使用时出现错误.

I am getting an error when I try and combine using expression with do.call and plot.

 x <- 1:10
 y <- x^1.5

我可以只使用plot函数来获得想要的图:

I can get the plot I want by using only the plot function:

plot(y~x,xlab=expression(paste("Concentration (",mu,"M)")))

但是,我想使用do.call来实现我的绘图.我有很长的参数列表,它们以列表形式存储在p中.但是,当我尝试将列表传递给do.call时,出现以下错误:

However, I would like to implement my plot using do.call. I have a really long list of parameters stored as a list, p. However, when I try and pass the list to do.call I get the following error:

p <- list(xlab=expression(paste("Concentration (",mu,"M)")))
do.call(plot,c(y~x,p))
Error in paste("Concentration (", mu, "M)") : 
  object 'mu' not found

我还尝试在传递给do.call的args中明确定义公式. IE. do.call(plot,c(formula=y~x,p)).我不明白为什么会收到错误消息-特别是因为以下内容没有给出错误消息:

I also tried defining the formula explicitly in the args passed to do.call. ie. do.call(plot,c(formula=y~x,p)). I do not understand why I am getting the error - especially because the following does not give an error:

do.call(plot,c(0,p))

(并在x轴上给出所需的mu字符).

(and gives the desired mu character in the xaxis).

推荐答案

do.call在运行函数之前先评估参数;尝试将表达式包装在quote:

do.call evaluates the parameters before running the function; try wrapping the expression in quote:

p <- list(xlab=quote(expression(paste("Concentration (",mu,"M)"))))
do.call("plot", c(y~x, p))

这篇关于如何结合do.call()plot()和expression()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆