【发布时间】:2014-11-01 19:06:34
【问题描述】:
所有,我的任务是编写一个返回列表作为输出的函数。 同时,绘制一些东西。
使用mtcars数据说我的功能如下
library(ggplot2)
data(mtcars)
myfunc<-function(mtcars){
for(i in 1:ncol(mtcars)){
g1<- ggplot(mtcars, aes(x=mtcars[,i]))
g1 + geom_histogram()+
geom_vline(xintercept=mean(mtcars[,i]),col="red")
}
return (list(mtcars))
}
myfunc(mtcars)
我怎样才能修改上面的代码,返回一个想要的列表并显示gglots?
【问题讨论】:
-
data.frames 列表,在我的示例中,我只是将原始数据作为列表返回。这只是一个例子
-
@jlhoward 如果您能解决,将不胜感激,谢谢。
标签: r function ggplot2 dataframe histogram