ggplot2 中的 qplot 中的平滑错误

发布于 2024-09-04 04:57:47 字数 800 浏览 1 评论 0原文

我有一些数据试图按其类型绘制多面图,并叠加平滑的(黄土、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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

篱下浅笙歌 2024-09-11 04:57:47

这对我有用。确定你有最新版本的 ggplot2 吗?

It works for me. Are sure you have the latest version of ggplot2?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文