ggplot2 中的 qplot 中的平滑错误
我有一些数据试图按其类型绘制多面图,并叠加平滑的(黄土、LM 等)。生成代码如下:
testFrame <- data.frame(Time=sample(20:60,50,replace=T),Dollars=round(runif(50,0,6)),Type=sample(c("First","Second","Third","Fourth"),50,replace=T,prob=c(.33,.01,.33,.33)))
我可以制作多面图或绘制平滑图,但我不能同时做这两者。下面的前三行代码工作正常。第四行是我遇到麻烦的地方:
qplot(Time,Dollars,data=testFrame,colour=Type)
qplot(Time,Dollars,data=testFrame,colour=Type) + geom_smooth()
qplot(Time,Dollars,data=testFrame) + facet_wrap(~Type)
qplot(Time,Dollars,data=testFrame) + facet_wrap(~Type) + geom_smooth()
它给出了以下错误:
[<-.data.frame
(*tmp*
, var, value = list(NA
= NULL)) 中出现错误: 数据框的下标分配中不允许缺失值
在多面图中叠加平滑时我缺少什么?我可以发誓我以前做过这件事,甚至可能使用相同的数据。
I have some data that I am trying to plot faceted by its Type with a smooth (Loess, LM, whatever) superimposed. Generation code is below:
testFrame <- data.frame(Time=sample(20:60,50,replace=T),Dollars=round(runif(50,0,6)),Type=sample(c("First","Second","Third","Fourth"),50,replace=T,prob=c(.33,.01,.33,.33)))
I have no problem either making a faceted plot, or plotting the smooth, but I cannnot do both. The first three lines of code below work fine. The fourth line is where I have trouble:
qplot(Time,Dollars,data=testFrame,colour=Type)
qplot(Time,Dollars,data=testFrame,colour=Type) + geom_smooth()
qplot(Time,Dollars,data=testFrame) + facet_wrap(~Type)
qplot(Time,Dollars,data=testFrame) + facet_wrap(~Type) + geom_smooth()
It gives the following error:
Error in
[<-.data.frame
(*tmp*
, var, value = list(NA
= NULL)) :
missing values are not allowed in subscripted assignments of data frames
What am I missing to overlay a smooth in a faceted plot? I could have sworn I had done this before, possibly even with the same data.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这对我有用。确定你有最新版本的 ggplot2 吗?
It works for me. Are sure you have the latest version of ggplot2?