I would like to produce a scatter plot with ggplot2, which contains both a regression line through all data points (regardless which group they are from), but at the same time varies the shape of the markers by the grouping variable. The code below produces the group markers, but comes up with TWO regression lines, one for each group.
#model=lm(df, ParamY~ParamX)
p1<-ggplot(df,aes(x=ParamX,y=ParamY,shape=group)) + geom_point() + stat_smooth(method=lm)
How can I program that?
you shouldn't have to redo your full
aes
in thegeom_point
and add another layer, just move the shapeaes
to thegeom_point
call:EDIT:
To help with your comment:
because
annotate
can end up, for me anyway, with the same labels on each facet. I like to make a minidata.frame
that has my variable for faceting and the facet levels with another column representing the labels I want to use. In this case the label data frame is calleddfalbs
.Then use this to label data frame to label the facets individually e.g.