【发布时间】:2014-10-02 09:30:49
【问题描述】:
我正在尝试在 ggplot2 中编写一个函数并获取此错误消息:
layout_base 中的错误(数据、变量、drop = drop):
至少一层必须包含用于分面的所有变量
这是我的代码:
growth.plot<-function(data,x,y,fac){
gp <- ggplot(data = data,aes(x = x, y = y))
gp <- gp + geom_point() + facet_wrap(~ fac)
return(gp)
}
growth.plot(data=mydata, x=x.var, y=y.var,fac= fac.var)
如果我尝试不使用该功能,则情节会完美显示
gp1 <- ggplot(data = mydata,aes(x = x.var), y = y.var))
gp1+ geom_point()+ facet_wrap(~ fac.var) # this works
【问题讨论】:
-
看看
aes_string。 -
谢谢,我试过了,可惜没用。
-
我认为this answer 可能是您要找的。span>