Dear ggplot users,
I am trying to create a box plot with smooth line with the code below, which was successful with a smaller dataset (example plot is below), but I got error when I used the same code but with a larger dataset.

p <- ggplot(d, aes(time, Resp)) + geom_boxplot()
p + facet_grid(.~trt) + geom_smooth(aes(group = 1))
The error message was:
Error in smooth.construct.cr.smooth.spec(object, data, knots) :
x has insufficient unique values to support 10 knots: reduce k.
So, I googled any help to solve this, and I came to R-help communication using below:
## summary function ##
stat_sum_single <- function(fun, geom="point", ...) {
stat_summary(fun.y=fun, colour="red", geom=geom, size = 3, ...)
}
stat_sum_df <- function(fun, geom="crossbar", ...) {
stat_summary(fun.data=fun, colour="red", geom=geom, width=0.2, ...)
}
## example from ggplot web page
c <- qplot(cyl, mpg, data=mtcars)
c + stat_summary(fun.data = "mean_cl_boot", colour = "red")
c + stat_sum_single(mean, geom="line")
c + stat_sum_df("mean_cl_normal", geom = "smooth")
However, it seems to me it is not working if x-variable is factor.
#if cyl is factor?
c <- qplot(as.factor(cyl), mpg, data=mtcars)
c <- c + geom_boxplot() #creat box plot
c + stat_summary(fun.data = "mean_cl_boot", colour = "red")
c + stat_sum_single(mean, geom="line") #did't work
c + stat_sum_df("mean_cl_normal", geom = "smooth") #didn't work
If I want to create a box plot overlay with smooth line (or mean line), in this case, x-variable should be factor variable. I also don’t know why geom_smooth(aes(group = 1)) didn’t work (is there any way to reduce “knot”? ).
Have anyone had the same problem? Any help would be appreciated.
Regards,
Kaori
--
You received this message because you are subscribed to the ggplot2 mailing list.
Please provide a reproducible example: http://gist.github.com/270442
To post: email ggp...@googlegroups.com
To unsubscribe: email ggplot2+u...@googlegroups.com
More options: http://groups.google.com/group/ggplot2
Hi Dennis,
You saved me again…thank you!!
Kaori