I am working with a data frame in R that looks like this:
NEI_BaltLaVeh
'data.frame': 6497651 obs. of 6 variables:
$ fips : chr "09001" "09001" "09001" "09001" ...
$ SCC : chr "10100401" "10100404" "10100501" "10200401" ...
$ Pollutant: chr "PM25-PRI" "PM25-PRI" "PM25-PRI" "PM25-PRI" ...
$ Emissions: num 15.714 234.178 0.128 2.036 0.388 ...
$ type : chr "POINT" "POINT" "POINT" "POINT" ...
$ year : int 1999 1999 1999 1999 1999 1999 1999 1999 1999 1999 ...
Using ggplot I am looking at the total emissions(using the "sum" feature in stat_summary) over time for two different areas(different "fips" codes) using:
g<-ggplot(NEI_BaltLaVeh, aes(year, Emissions, colour=fips))
g+ stat_summary(fun.y="sum", geom="point")
This works fine. However, I would also like to apply the geom_smooth linear fit function to these to juxtaposed data sets. Its clear that just calling:
g+ stat_summary(fun.y="sum", geom="point")+geom_smooth(method="lm")
applies geom_smooth to the original data set sent to ggplot before it was transformed by stat_summary giving me this plot:
Is there an elegant way for me to apply geom_smooth to the transformed data without having to go back and manipulate the data?