I'm having trouble articulating this question. I have a dataset with daily income and expense for several years. I have been trying a few approaches so there are a lot of date columns now.
> str(df)
'data.frame': 3047 obs. of 8 variables:
$ Date : Factor w/ 1219 levels "2014-05-06T00:00:00.0000000",..: 6 9 2 3 4 6 10 11 13 14 ...
$ YearMonthnumber : Factor w/ 44 levels "2014/05","2014/06",..: 1 1 1 1 1 1 1 1 1 1 ...
$ cat : Factor w/ 10 levels "Account Adjustment",..: 1 2 3 3 3 3 3 3 3 3 ...
$ Value : num 2.2 277.7 20 14.1 6.8 ...
$ Income_or_expense: Factor w/ 2 levels "Expense","Income": 1 1 1 1 1 1 1 1 1 1 ...
$ ddate : Date, format: "2014-05-16" "2014-05-19" "2014-05-12" "2014-05-13" ...
$ monthly : Date, format: "2014-05-01" "2014-05-01" "2014-05-01" "2014-05-01" ...
Basically what I want to plot is:
- the sum of each month's income and the sum of each month's expense (ie the value column), where category (cat) is not "Transfer", coloured by income_or_expense
- plot a smoothed line through these summary points.
I can do step one, but not two. Here is what I have:
ggplot(data = subset(df, cat!="Transfer"), aes(x = monthly, y= Value, colour = Income_or_expense)) +
stat_summary(fun.y = sum, geom = "point") +
scale_x_date(labels = date_format("%Y-%m"))
How can I add a smooth geom to these resulting summary stats?
Edit: If I add + stat_summary(fun.y = sum, geom = "smooth"), the result is a line graph, not a smoothed model. And if I add it without fun.y = sum, then the smoothed line is based on daily values, not the monthly aggregates
Thanks.



stat_summary(geom = 'smooth'+ stat_summary(fun.y = sum, geom = "smooth"), the result is basically a line graph, not a smoothed model. And if I add it withoutfun.y = sum, then the smoothed line is based on daily values, not the monthly aggregates.