I work with R and ggplot. I have already drawn point for 4 different data.frames. And now I want to draw 4 regression lines for this points sets.
My previous code:
ggplot() +
ggtitle("title")+
xlab("date") +
ylab("value") +
geom_point(data=toplot$1, aes(x=date, y=x, color='1'), size = 4, shape=1) +
geom_point(data=toplot$2, aes(x=date, y=x, color='2'), size = 4, shape=2)+
geom_point(data=toplot$3, aes(x=date, y=x, color='3'), size = 4, shape=3)+
geom_point(data=toplot$4, aes(x=date, y=x, color='4'), size = 4, shape=4)+
scale_colour_manual(name = "legend", values = c('1'='green', "2"="red", "3"="blue", "4"="brown"))
When I add a line for the first data.frame
geom_smooth(data=toplot$1, formula=date~x,method=lm, color='1',aes(x=date, y=x))
I receive a message:
Only one unique x value each group.Maybe you want aes(group = 1)
If I add line:
geom_smooth(data=toplot$1, formula=date~x,method=lm, color='1',aes(group=1))
I receive another message:
stat_smooth requires the following missing aesthetics: x, y
May be you know, what I need to write as aes argument (without any aes it also doesn't work).
Thank you.