我想要一个带有数据名称(dat)、因子(myfactor)、变量名称(myvar)等参数的函数来动态生成直方图(必须使用点阵图)。
以 IRIS 为例:
data(iris)
my_histogram <- function(myvar,myfactor,dat){
listofparam <- c(myvar,myfactor)
myf <- as.formula(paste("~",paste(listofparam,collapse="|")))
histogram(myf,
data=dat,
main=bquote(paste(.(myvar),"distribution by",.(myfactor),seq=" ")))}
my_histogram("Sepal.Length","Species","iris")
正如一些帖子所示,我也尝试了 do.call:
my_histogram <- function(myvar,myfactor,dat){
listofparam <- c(myvar,myfactor)
myf <- as.formula(paste("~",paste(listofparam,collapse="|")))
p <- do.call("histogram",
args = list(myf,
data=dat))
print(p)
}
my_histogram("Sepal.Length","Species","iris")
但是出现错误:invalid 'envir' argument of type 'character'. I think the program doesn't know where to look for this
myf`字符串。我该如何解决这个问题或有更好的方法?