I'm creating a scatterplot in ggplot
where I am classifying the points based on company point. I would like to add a single trend line which shows the regression of all points. However, when I add geom_smooth()
it adds a trend line for each class. How can I modify this so that I can show both the classes via the colors of the points and a single trend line that performs a regression of all data points regardless of class?
Here is some sample data:
ff<-as.data.frame(cbind(Energy_YearsToAchieve=c(5,10,15,13,10,8),Energy_Change=c(10,12,28,25,15,10), Sector_4C=c("A","B","C","A","B","B")))
ggplot(ff, aes(x=Energy_YearsToAchieve, y=Energy_Change, color=Sector_4C)) +
geom_point()+
geom_smooth(method=lm, se=FALSE, fullrange=FALSE,aes(group=Sector_4C))