I want to sum a value by week. Sometimes the first or last week will have less than 7 days. In the example below the data starts with 2016-01-01, but the floor date for that week is 2015-12-27. So the weekly sum is based on two days instead of seven. I understand that this behaviour is completely logical, but i would like, that the first and last week (that might consist of less than 7 days of data) don´t show as low values in the plot. How can i do this? Should i omit the first and last week? Should i use an average value here? How?
expenses <- data_frame(
date=seq(as.Date("2016-01-01"), as.Date("2016-12-31"), by=1),
amount=rgamma(length(date), shape = 2, scale = 20))
plot_df <- expenses %>%
mutate(Week = floor_date(date, "week")) %>%
group_by(Week) %>%
summarize(exp_sum = sum(amount))
ggplot(data = plot_df,
aes(x = as.Date(Week), y = exp_sum)) +
geom_line() +
geom_point() +
scale_x_date(date_breaks = "1 week", date_labels = "%W")