While looking at this issue, I couldn't specify a custom linear model to geom_smooth
. My code is as follows:
example.label <- c("A","A","A","A","A","B","B","B","B","B")
example.value <- c(5, 4, 4, 5, 3, 8, 9, 11, 10, 9)
example.age <- c(30, 40, 50, 60, 70, 30, 40, 50, 60, 70)
example.score <- c(90,95,89,91,85,83,88,94,83,90)
example.data <- data.frame(example.label, example.value,example.age,example.score)
p = ggplot(example.data, aes(x=example.age,
y=example.value,color=example.label)) +
geom_point()
#geom_smooth(method = lm)
cf = function(dt){
lm(example.value ~example.age+example.score, data = dt)
}
cf(example.data)
p_smooth <- by(example.data, example.data$example.label,
function(x) geom_smooth(data=x, method = lm, formula = cf(x)))
p + p_smooth
I am getting this error/warning:
Warning messages:
1: Computation failed in `stat_smooth()`:
object 'weight' not found
2: Computation failed in `stat_smooth()`:
object 'weight' not found
Why am I getting this? And what is the proper method of specifying a custom model to geom_smooth
. Thanks.