Smooth Error in qplot from ggplot2

Posted by Jared on Stack Overflow See other posts from Stack Overflow or by Jared
Published on 2010-06-01T23:15:58Z Indexed on 2010/06/01 23:23 UTC
Read the original article Hit count: 496

Filed under:
|
|
|
|

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.

© Stack Overflow or respective owner

Related posts about ggplot2

Related posts about rstats