Notebook
## rpy2 doesn't seem to handle datetime.date objects very well, so we make it a string commons_searches_daily['log_date_str'] = commons_searches_daily['log_date'].apply(str)%%R ## Moving average function with right-alignment and zero-fill mavg = function(x, ndays) { rollapply(x, ndays, mean, align = 'right', fill = 0) } ## Color-blind-friendly palette with black ## http://www.cookbook-r.com/Graphs/Colors_(ggplot2)/ cbbPalette <- c("#000000", "#E69F00", "#56B4E9", "#009E73", "#F0E442", "#0072B2", "#D55E00", "#CC79A7")%%R -i commons_searches_daily commons_searches_daily %>% mutate(log_date = ymd(log_date_str)) %>% filter(log_date < today(tzone = 'UTC')) %>% ## skip today because it's partial data arrange(log_date) %>% mutate(n_autocomp_m7 = mavg(n_autocomp, 7)) %>% ggplot(aes(x = log_date)) + scale_y_continuous(labels = compress) + scale_x_date(date_breaks = "1 month", minor_breaks = NULL, date_labels = "%b\n%Y") + labs(x = "Date", y = "Number of searches", title = "Autocomplete searches per day with 7-day MA") + geom_line(aes(y = n_autocomp)) + geom_line(aes(y = n_autocomp_m7), color = cbbPalette[2]) + commons_theme()%%R -i commons_searches_daily commons_searches_daily %>% mutate(log_date = ymd(log_date_str)) %>% filter(log_date < today(tzone = 'UTC')) %>% ## skip today because it's partial data arrange(log_date) %>% mutate(n_fulltext_successful_m7 = mavg(n_fulltext_successful, 7)) %>% ggplot(aes(x = log_date)) + scale_y_continuous(labels = compress) + scale_x_date(date_breaks = "1 month", minor_breaks = NULL, date_labels = "%b\n%Y") + labs(x = "Date", y = "Number of searches", title = "Successful Fulltext searches per day with 7-day MA") + geom_line(aes(y = n_fulltext_successful)) + geom_line(aes(y = n_fulltext_successful_m7), color = cbbPalette[2]) + commons_theme()%%R -i commons_searches_daily commons_searches_daily %>% mutate(log_date = ymd(log_date_str)) %>% filter(log_date < today(tzone = 'UTC')) %>% ## skip today because it's partial data arrange(log_date) %>% mutate(n_fulltext_zeroresults_m7 = mavg(n_fulltext_zeroresults, 7)) %>% ggplot(aes(x = log_date)) + scale_y_continuous(labels = compress) + scale_x_date(date_breaks = "1 month", minor_breaks = NULL, date_labels = "%b\n%Y") + labs(x = "Date", y = "Number of searches", title = "Zero-results Fulltext searches per day with 7-day MA") + geom_line(aes(y = n_fulltext_zeroresults)) + geom_line(aes(y = n_fulltext_zeroresults_m7), color = cbbPalette[2]) + commons_theme()