Adan - Here's the example I promised...it is one of the first functions I did. For my work I have occasion to analyze survey information. It's not really all that different from what is in Hadley's rpub page so I guess that's a good sign for me.
The call is average_and_plot_geo_smooth(surveys_to_include, prod_var)
and the function is...
average_and_plot_geo_smooth <- function (df, prod_group){
df %>% filter (!is.na(major_geo)) %>%
select (case_number, ends_with("sat"), product_csat, day_week_year, major_geo) %>%
group_by(day_week_year, major_geo) %>%
summarize (avg_ttr_sat = mean(ttr_sat, na.rm = TRUE),
avg_knowledge_sat = mean(tse_knowledge_sat, na.rm=TRUE))%>%
gather (key = metric, value = measurement, avg_ttr_sat, avg_knowledge_sat) %>%
ggplot (aes(x=day_week_year, y= measurement, color = major_geo)) +
stat_smooth(method = "loess", span=0.50, n = 10, na.rm=TRUE, se=FALSE) +
facet_wrap (~metric) +
scale_color_manual(values = c("red", "purple", "blue")) +
labs (x = "Month", y="Smoothed Score", color = "Contact Geo")