我正在使用R中的数据框,如下所示:
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 ...
使用ggplot我正在查看总排放(使用stat_summary中的“sum”功能)随着时间的推移,使用以下两个不同的区域(不同的“fips”代码):
g<-ggplot(NEI_BaltLaVeh, aes(year, Emissions, colour=fips))
g+ stat_summary(fun.y="sum", geom="point")
这很好用。但是,我还想将geom_smooth线性拟合函数应用于这些并置数据集。很明显,只需要打电话:
g+ stat_summary(fun.y="sum", geom="point")+geom_smooth(method="lm")
将geom_smooth应用于发送到ggplot的原始数据集,然后由stat_summary转换为ggplot给我这个情节:
我是否有一种优雅的方式可以将geom_smooth应用于转换后的数据,而无需返回并操作数据?