I try to add my (multiple) linear regression lines on my ggplot. I have two dummies (morning-evening) for the morning.dummy. The plot is correct but it gives me an error when I want to add the regression lines. Here is the code:
regression_1 <- lm(weight ~ morning.dummy + dayNumber + (morning.dummy*dayNumber) +
I(dayNumber^2) + (I(dayNumber^2)*morning.dummy),
data=weight_data)
summary(regression_1)
#plot
plot2 <- ggplot(data=weight_data,aes(x=dayNumber, y=weight, color=morning.dummy)) +
geom_point()+
stat_smooth(method = "lm", formula = weight ~ morning.dummy + dayNumber + (morning.dummy*dayNumber) +I(dayNumber^2) + (I(dayNumber^2)*morning.dummy), size = 1) +
labs(y = "Weight in kg", x = "Day Number of weight measurment", subtitle = "Day 0 = 3 October 2010")
plot2
This is the error:
Error in grid.Call.graphics(C_setviewport, vp, TRUE) :
non-finite location and/or size for viewport
In addition: Warning message:
Computation failed in `stat_smooth()`:
object 'dayNumber' not found
Does someone have an idea where I do something wrong?