From b853139fe52f4a53069065ee06b26e73f6d26905 Mon Sep 17 00:00:00 2001 From: Chris Salvato Date: Wed, 8 Jun 2016 15:09:55 -0400 Subject: [PATCH 1/5] Remove hour of day from keyword performance report. It doesn't work. --- AdWordsUtilities/R/raw_keyword_performance_data.r | 1 - 1 file changed, 1 deletion(-) diff --git a/AdWordsUtilities/R/raw_keyword_performance_data.r b/AdWordsUtilities/R/raw_keyword_performance_data.r index 676f6d0..26f7994 100644 --- a/AdWordsUtilities/R/raw_keyword_performance_data.r +++ b/AdWordsUtilities/R/raw_keyword_performance_data.r @@ -19,7 +19,6 @@ raw_keyword_performance_data <- function(from=Sys.Date(), to=Sys.Date()) { statement <- statement(select=c( 'Date', 'DayOfWeek', - # 'HourOfDay', 'Criteria', 'Status', 'CampaignId', From 3888ac6b864c565168f955809a2f9995d1191511 Mon Sep 17 00:00:00 2001 From: Chris Salvato Date: Wed, 8 Jun 2016 15:10:11 -0400 Subject: [PATCH 2/5] Change transaction dates function to use heroku db, not data warehouse. --- PowerSupplyUtilities/R/get_first_transaction_dates_for_users.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PowerSupplyUtilities/R/get_first_transaction_dates_for_users.R b/PowerSupplyUtilities/R/get_first_transaction_dates_for_users.R index 0eda1a5..4142bbe 100644 --- a/PowerSupplyUtilities/R/get_first_transaction_dates_for_users.R +++ b/PowerSupplyUtilities/R/get_first_transaction_dates_for_users.R @@ -19,7 +19,7 @@ get_first_transaction_dates_for_users <- function(from=Sys.Date(), to=Sys.Date(), users = NULL, database_driver="database_drivers/postgresql-9.4.1208.jre6.jar", - jdbc_config_file="jdbc_data_warehouse_database_config.txt"){ + jdbc_config_file="jdbc_transactions_database_config.txt"){ if(file.exists(database_driver)) { require(RJDBC) From 824119e08e01c9ca9e543040c23a4b4be80a32cb Mon Sep 17 00:00:00 2001 From: Chris Salvato Date: Fri, 10 Jun 2016 17:26:16 -0400 Subject: [PATCH 3/5] Update gitignore to exclude output files --- .gitignore | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 1dcabe9..3afa096 100644 --- a/.gitignore +++ b/.gitignore @@ -11,4 +11,5 @@ jdbc_*.txt adwords_credentials.txt *.yml temp_*.txt -*.yml \ No newline at end of file +*.yml +output/* \ No newline at end of file From 429a6235b7737389f480875fea81a60ad436b848 Mon Sep 17 00:00:00 2001 From: Chris Salvato Date: Mon, 13 Jun 2016 09:31:53 -0400 Subject: [PATCH 4/5] Create file output for all plots that are generated --- .../R/click_through_rate_over_time.r | 9 +-- .../R/desktop_gdn_performance_over_time.r | 9 ++- .../R/desktop_performance_over_time.r | 19 ++++--- .../R/impression_share_over_time.r | 26 +++++---- .../keywords_campaign_performance_over_time.r | 10 +++- .../R/keywords_performance_over_time.r | 8 ++- .../R/mobile_gdn_performance_over_time.r | 9 ++- .../R/mobile_performance_over_time.r | 18 +++--- .../R/overall_performance_over_time.r | 7 ++- .../man/click_through_rate_over_time.Rd | 5 +- .../man/desktop_performance_over_time.Rd | 4 +- .../man/impression_share_over_time.Rd | 4 +- ...keywords_campaign_performance_over_time.Rd | 5 +- .../man/mobile_performance_over_time.Rd | 4 +- .../man/overall_performance_over_time.Rd | 5 +- .../R/click_through_rate_over_time.r | 10 ++-- .../R/desktop_performance_over_time.r | 19 ++++--- .../keywords_campaign_performance_over_time.r | 12 ++-- .../R/keywords_performance_over_time.r | 12 ++-- .../R/mobile_performance_over_time.r | 9 ++- .../R/overall_performance_over_time.r | 9 +-- .../man/click_through_rate_over_time.Rd | 7 ++- .../man/desktop_performance_over_time.Rd | 2 + ...keywords_campaign_performance_over_time.Rd | 5 +- .../man/keywords_performance_over_time.Rd | 5 +- .../man/mobile_performance_over_time.Rd | 4 +- .../man/overall_performance_over_time.Rd | 9 ++- PowerSupplyUtilities/R/orders_per_week.r | 10 +++- PowerSupplyUtilities/R/paleo_cohort_views.r | 19 ++++--- .../R/search_engine_marketing_report.r | 57 ++++++++++--------- SalvatoUtilities/NAMESPACE | 1 + overview_report.r | 3 +- 32 files changed, 206 insertions(+), 129 deletions(-) diff --git a/AdWordsUtilities/R/click_through_rate_over_time.r b/AdWordsUtilities/R/click_through_rate_over_time.r index 397ca55..f7c55a9 100644 --- a/AdWordsUtilities/R/click_through_rate_over_time.r +++ b/AdWordsUtilities/R/click_through_rate_over_time.r @@ -4,12 +4,13 @@ #' #' @param keywords_elog A data frame containing keywords and transaction event log data. #' @param plot logical. If TRUE, creates a plot of the data. If false, creates no plot, Defaults to \code{TRUE}. +#' @param plot_png_file String with the path to the plot file that should be written. If NULL, no file is written. Defaults to \code{NULL}. #' @return The data frame used to create a plot of clickthrough rate over time. #' @export #' @examples #' overall_performance_over_time(elog_data_frame) -click_through_rate_over_time <- function(keywords_elog, plot = TRUE){ +click_through_rate_over_time <- function(keywords_elog, plot = TRUE, plot_png_file=NULL){ require(plyr) require(dplyr) keywords_weekly_conversion_metrics <- keywords_elog %>% @@ -23,8 +24,7 @@ click_through_rate_over_time <- function(keywords_elog, plot = TRUE){ if( plot ) { require(ggplot2) - plot( - ggplot( + the_plot <- ggplot( keywords_weekly_conversion_metrics %>% # Filter by a single keyword, and only include the previous 4 weeks of data. filter(week >= Sys.Date() - weeks(4), week <= Sys.Date(), keyword == "paleo meals"), @@ -33,7 +33,8 @@ click_through_rate_over_time <- function(keywords_elog, plot = TRUE){ ggtitle("AdWords - Weekly CTR by Keyword") + # ylim(0, 0.30) + facet_wrap(~keyword, ncol=2) - ) + + report.plot( the_plot, plot_png_file ) } return(keywords_weekly_conversion_metrics) diff --git a/AdWordsUtilities/R/desktop_gdn_performance_over_time.r b/AdWordsUtilities/R/desktop_gdn_performance_over_time.r index 54dd42d..4332565 100644 --- a/AdWordsUtilities/R/desktop_gdn_performance_over_time.r +++ b/AdWordsUtilities/R/desktop_gdn_performance_over_time.r @@ -4,6 +4,7 @@ #' #' @param gdn_elog A data frame containing keywords and transaction event log data. #' @param campaign_filter Optional. (e.g. "Paleo Performers") If provided, generates a data frame and plot for campaigns where the string is included in the campaign name. Default to NULL. +#' @param plot_png_file String with the path to the plot file that should be written. If NULL, no file is written. Defaults to \code{NULL}. #' @param plot logical. If TRUE, creates a plot of the data. If false, creates no plot, Defaults to \code{TRUE}. #' @return The data frame used to create a plot of mobile performance over time. #' @export @@ -12,7 +13,8 @@ desktop_gdn_performance_over_time <- function( gdn_elog, campaign_filter=NULL, - plot = TRUE){ + plot = TRUE, + plot_png_file=NULL){ require(plyr) require(dplyr) require(SalvatoUtilities) @@ -30,11 +32,12 @@ desktop_gdn_performance_over_time <- function( gdn_elog, if( plot ) { require(ggplot2) - plot(ggplot(devices_over_time %>% + the_plot <- ggplot(devices_over_time %>% filter(device == "dt"), aes(week,value,group=type,col=type,fill=type)) + geom_line() + - ggtitle("GDN Trends on Desktop")) + ggtitle("GDN Trends on Desktop") + report.plot(the_plot, plot_png_file) } return(devices_over_time) diff --git a/AdWordsUtilities/R/desktop_performance_over_time.r b/AdWordsUtilities/R/desktop_performance_over_time.r index 10a3043..d22ecdb 100644 --- a/AdWordsUtilities/R/desktop_performance_over_time.r +++ b/AdWordsUtilities/R/desktop_performance_over_time.r @@ -5,6 +5,7 @@ #' @param keywords_elog A data frame containing keywords and transaction event log data. #' @param keyword_filter Optional. (e.g. "paleo meals") If provided, generates a data frame and plot only for the *exact* keyword provided. Default to NULL. #' @param campaign_filter Optional. (e.g. "Paleo Performers") If provided, generates a data frame and plot for campaigns where the string is included in the campaign name. Default to NULL. +#' @param plot_png_file String with the path to the plot file that should be written. If NULL, no file is written. Defaults to \code{NULL}. #' @param plot logical. If TRUE, creates a plot of the data. If false, creates no plot, Defaults to \code{TRUE}. #' @return The data frame used to create a plot of desktop performance rate over time. #' @export @@ -14,7 +15,8 @@ desktop_performance_over_time <- function( keywords_elog, keyword_filter=NULL, campaign_filter=NULL, - plot = TRUE){ + plot = TRUE, + plot_png_file=NULL){ require(plyr) require(dplyr) require(SalvatoUtilities) @@ -38,13 +40,14 @@ desktop_performance_over_time <- function( keywords_elog, if( plot ) { require(ggplot2) - plot(ggplot(devices_over_time %>% - filter(keyword %in% earnings_keywords$keyword) %>% - filter(device == "dt"), - aes(week,value,group=type,col=type,fill=type)) + - geom_line() + - ggtitle("AdWords - Keyword Trends on Desktop") + - facet_wrap(~keyword + device, ncol=3)) + the_plot <- ggplot(devices_over_time %>% + filter(keyword %in% earnings_keywords$keyword) %>% + filter(device == "dt"), + aes(week,value,group=type,col=type,fill=type)) + + geom_line() + + ggtitle("AdWords - Keyword Trends on Desktop") + + facet_wrap(~keyword + device, ncol=3) + report.plot(the_plot, plot_png_file) } return(devices_over_time) diff --git a/AdWordsUtilities/R/impression_share_over_time.r b/AdWordsUtilities/R/impression_share_over_time.r index b509964..c438a0e 100644 --- a/AdWordsUtilities/R/impression_share_over_time.r +++ b/AdWordsUtilities/R/impression_share_over_time.r @@ -4,12 +4,13 @@ #' #' @param keywords_elog A data frame containing keywords and transaction event log data. #' @param plot logical. If TRUE, creates a plot of the data. If false, creates no plot, Defaults to \code{TRUE}. +#' @param plot_png_file String with the path to the plot file that should be written. If NULL, no file is written. Defaults to \code{NULL}. #' @return The data frame used to create a plot of impression share over time over time. #' @export #' @examples #' overall_performance_over_time(elog_data_frame) -impression_share_over_time <- function(keywords_elog, plot = TRUE){ +impression_share_over_time <- function(keywords_elog, plot = TRUE, plot_png_file=NULL){ require(plyr) require(dplyr) keywords_weekly_conversion_metrics <- keywords_elog %>% @@ -23,17 +24,18 @@ impression_share_over_time <- function(keywords_elog, plot = TRUE){ if( plot ) { require(ggplot2) - plot( - ggplot( - keywords_weekly_conversion_metrics %>% - # Filter by a single keyword, and only include the previous 4 weeks of data. - filter(week >= Sys.Date() - weeks(4), week <= Sys.Date(), keyword == "paleo meals"), - aes(x=week, y=est_search_impression_share, fill=campaign_name)) + - geom_bar(stat="identity", position="dodge") + - ggtitle("AdWords - Weekly Impression Share by Geo") + - ylim(0, 1) + - facet_wrap(~keyword, ncol=2) - ) + + the_plot <- ggplot( + keywords_weekly_conversion_metrics %>% + # Filter by a single keyword, and only include the previous 4 weeks of data. + filter(week >= Sys.Date() - weeks(4), week <= Sys.Date(), keyword == "paleo meals"), + aes(x=week, y=est_search_impression_share, fill=campaign_name)) + + geom_bar(stat="identity", position="dodge") + + ggtitle("AdWords - Weekly Impression Share by Geo") + + ylim(0, 1) + + facet_wrap(~keyword, ncol=2) + + report.plot(the_plot, file=plot_png_file) } return(keywords_weekly_conversion_metrics) diff --git a/AdWordsUtilities/R/keywords_campaign_performance_over_time.r b/AdWordsUtilities/R/keywords_campaign_performance_over_time.r index bd4ca1d..a60168f 100644 --- a/AdWordsUtilities/R/keywords_campaign_performance_over_time.r +++ b/AdWordsUtilities/R/keywords_campaign_performance_over_time.r @@ -4,12 +4,15 @@ #' #' @param keywords_elog A data frame containing keywords and transaction event log data. #' @param plot logical. If TRUE, creates a plot of the data. If false, creates no plot, Defaults to \code{TRUE}. +#' @param plot_png_file String with the path to the plot file that should be written. If NULL, no file is written. Defaults to \code{NULL}. #' @return The data frame used to create a plot of performance over time. #' @export #' @examples #' keywords_campaign_performance_over_time(elog_data_frame) -keywords_campaign_performance_over_time <- function(keywords_elog, plot = TRUE){ +keywords_campaign_performance_over_time <- function(keywords_elog, + plot = TRUE, + plot_png_file=NULL){ require(plyr) require(dplyr) @@ -28,10 +31,11 @@ keywords_campaign_performance_over_time <- function(keywords_elog, plot = TRUE){ if( plot ) { require(ggplot2) - plot(ggplot(keywords_campaigns_over_time %>% filter(keyword == "paleo meals" & grepl("Paleo Performers",campaign_name)), aes(week,value,group=type,col=type,fill=type)) + + the_plot <- ggplot(keywords_campaigns_over_time %>% filter(keyword == "paleo meals" & grepl("Paleo Performers",campaign_name)), aes(week,value,group=type,col=type,fill=type)) + geom_line() + ggtitle("AdWords - Keyword Trends by Campaign") + - facet_wrap(~keyword + campaign_name, ncol=2)) + facet_wrap(~keyword + campaign_name, ncol=2) + report.plot(the_plot, plot_png_file) } return(keywords_campaigns_over_time) diff --git a/AdWordsUtilities/R/keywords_performance_over_time.r b/AdWordsUtilities/R/keywords_performance_over_time.r index 1932109..8ed6ee2 100644 --- a/AdWordsUtilities/R/keywords_performance_over_time.r +++ b/AdWordsUtilities/R/keywords_performance_over_time.r @@ -4,12 +4,13 @@ #' #' @param keywords_elog A data frame containing keywords and transaction event log data. #' @param plot logical. If TRUE, creates a plot of the data. If false, creates no plot, Defaults to \code{TRUE}. +#' @param plot_png_file String with the path to the plot file that should be written. If NULL, no file is written. Defaults to \code{NULL}. #' @return The data frame used to create a plot of performance over time. #' @export #' @examples #' keywords_performance_over_time(elog_data_frame) -keywords_performance_over_time <- function(keywords_elog, plot = TRUE){ +keywords_performance_over_time <- function(keywords_elog, plot = TRUE, plot_png_file=NULL){ require(plyr) require(dplyr) @@ -27,10 +28,11 @@ keywords_performance_over_time <- function(keywords_elog, plot = TRUE){ if( plot ) { require(ggplot2) - plot(ggplot(keywords_over_time, aes(week,value,group=type,col=type,fill=type)) + + the_plot <- ggplot(keywords_over_time, aes(week,value,group=type,col=type,fill=type)) + geom_line() + ggtitle("AdWords - Keyword Trends") + - facet_wrap(~keyword)) + facet_wrap(~keyword) + report.plot(the_plot, plot_png_file) } return(keywords_over_time) diff --git a/AdWordsUtilities/R/mobile_gdn_performance_over_time.r b/AdWordsUtilities/R/mobile_gdn_performance_over_time.r index 3731ae3..7a65fb0 100644 --- a/AdWordsUtilities/R/mobile_gdn_performance_over_time.r +++ b/AdWordsUtilities/R/mobile_gdn_performance_over_time.r @@ -4,6 +4,7 @@ #' #' @param gdn_elog A data frame containing keywords and transaction event log data. #' @param campaign_filter Optional. (e.g. "Paleo Performers") If provided, generates a data frame and plot for campaigns where the string is included in the campaign name. Default to NULL. +#' @param plot_png_file String with the path to the plot file that should be written. If NULL, no file is written. Defaults to \code{NULL}. #' @param plot logical. If TRUE, creates a plot of the data. If false, creates no plot, Defaults to \code{TRUE}. #' @return The data frame used to create a plot of mobile performance over time. #' @export @@ -12,7 +13,8 @@ mobile_gdn_performance_over_time <- function( gdn_elog, campaign_filter=NULL, - plot = TRUE){ + plot = TRUE, + plot_png_file=NULL){ require(plyr) require(dplyr) require(SalvatoUtilities) @@ -30,11 +32,12 @@ mobile_gdn_performance_over_time <- function( gdn_elog, if( plot ) { require(ggplot2) - plot(ggplot(devices_over_time %>% + the_plot <- ggplot(devices_over_time %>% filter(device == "mb"), aes(week,value,group=type,col=type,fill=type)) + geom_line() + - ggtitle("GDN Trends on Mobile")) + ggtitle("GDN Trends on Mobile") + report.plot( the_plot, plot_png_file ) } return(devices_over_time) diff --git a/AdWordsUtilities/R/mobile_performance_over_time.r b/AdWordsUtilities/R/mobile_performance_over_time.r index 915a349..ebb8b8f 100644 --- a/AdWordsUtilities/R/mobile_performance_over_time.r +++ b/AdWordsUtilities/R/mobile_performance_over_time.r @@ -5,6 +5,7 @@ #' @param keywords_elog A data frame containing keywords and transaction event log data. #' @param keyword_filter Optional. (e.g. "paleo meals") If provided, generates a data frame and plot only for the *exact* keyword provided. Default to NULL. #' @param campaign_filter Optional. (e.g. "Paleo Performers") If provided, generates a data frame and plot for campaigns where the string is included in the campaign name. Default to NULL. +#' @param plot_png_file String with the path to the plot file that should be written. If NULL, no file is written. Defaults to \code{NULL}. #' @param plot logical. If TRUE, creates a plot of the data. If false, creates no plot, Defaults to \code{TRUE}. #' @return The data frame used to create a plot of mobile performance over time. #' @export @@ -14,7 +15,9 @@ mobile_performance_over_time <- function( keywords_elog, keyword_filter=NULL, campaign_filter=NULL, - plot = TRUE){ + plot = TRUE, + plot_png_file=TRUE + ){ require(plyr) require(dplyr) require(SalvatoUtilities) @@ -35,13 +38,14 @@ mobile_performance_over_time <- function( keywords_elog, if( plot ) { require(ggplot2) - plot(ggplot(devices_over_time %>% + the_plot <- ggplot(devices_over_time %>% filter(device == "mb"), - aes(week,value,group=type,col=type,fill=type)) + - geom_line() + - ggtitle("AdWords - Keyword Trends on Mobile") + - ylim(-1000,1500) + - facet_wrap(~keyword + device, ncol=3)) + aes(week,value,group=type,col=type,fill=type)) + + geom_line() + + ggtitle("AdWords - Keyword Trends on Mobile") + + ylim(-1000,1500) + + facet_wrap(~keyword + device, ncol=3) + report.plot( the_plot, plot_png_file ) } return(devices_over_time) diff --git a/AdWordsUtilities/R/overall_performance_over_time.r b/AdWordsUtilities/R/overall_performance_over_time.r index 16a31eb..80058c9 100644 --- a/AdWordsUtilities/R/overall_performance_over_time.r +++ b/AdWordsUtilities/R/overall_performance_over_time.r @@ -4,12 +4,13 @@ #' #' @param keywords_elog A data frame containing keywords and transaction event log data. #' @param plot logical. If TRUE, creates a plot of the data. If false, creates no plot, Defaults to \code{TRUE}. +#' @param plot_png_file String with the path to the plot file that should be written. If NULL, no file is written. Defaults to \code{NULL}. #' @return The data frame used to create a plot of performance over time. #' @export #' @examples #' overall_performance_over_time(elog_data_frame) -overall_performance_over_time <- function(keywords_elog, plot = TRUE){ +overall_performance_over_time <- function(keywords_elog, plot = TRUE, plot_png_file=NULL){ require(plyr) require(dplyr) all_keyword_ROAS_over_time <- keywords_elog %>% @@ -23,10 +24,10 @@ overall_performance_over_time <- function(keywords_elog, plot = TRUE){ if( plot ) { require(ggplot2) - plot(ggplot(all_keyword_ROAS_over_time, + the_plot <- ggplot(all_keyword_ROAS_over_time, aes(week,value,group=type,col=type,fill=type)) + geom_line() - ) + report.plot( the_plot, plot_png_file ) } return(all_keyword_ROAS_over_time) diff --git a/AdWordsUtilities/man/click_through_rate_over_time.Rd b/AdWordsUtilities/man/click_through_rate_over_time.Rd index 01f368d..96ec998 100644 --- a/AdWordsUtilities/man/click_through_rate_over_time.Rd +++ b/AdWordsUtilities/man/click_through_rate_over_time.Rd @@ -4,12 +4,15 @@ \alias{click_through_rate_over_time} \title{Create plot of AdWords click through rate over time} \usage{ -click_through_rate_over_time(keywords_elog, plot = TRUE) +click_through_rate_over_time(keywords_elog, plot = TRUE, + plot_png_file = NULL) } \arguments{ \item{keywords_elog}{A data frame containing keywords and transaction event log data.} \item{plot}{logical. If TRUE, creates a plot of the data. If false, creates no plot, Defaults to \code{TRUE}.} + +\item{plot_png_file}{String with the path to the plot file that should be written. If NULL, no file is written. Defaults to \code{NULL}.} } \value{ The data frame used to create a plot of clickthrough rate over time. diff --git a/AdWordsUtilities/man/desktop_performance_over_time.Rd b/AdWordsUtilities/man/desktop_performance_over_time.Rd index 8eacdfd..5a27de1 100644 --- a/AdWordsUtilities/man/desktop_performance_over_time.Rd +++ b/AdWordsUtilities/man/desktop_performance_over_time.Rd @@ -5,7 +5,7 @@ \title{Create plot of AdWords desktop performance over time} \usage{ desktop_performance_over_time(keywords_elog, keyword_filter = NULL, - campaign_filter = NULL, plot = TRUE) + campaign_filter = NULL, plot = TRUE, plot_png_file = NULL) } \arguments{ \item{keywords_elog}{A data frame containing keywords and transaction event log data.} @@ -15,6 +15,8 @@ desktop_performance_over_time(keywords_elog, keyword_filter = NULL, \item{campaign_filter}{Optional. (e.g. "Paleo Performers") If provided, generates a data frame and plot for campaigns where the string is included in the campaign name. Default to NULL.} \item{plot}{logical. If TRUE, creates a plot of the data. If false, creates no plot, Defaults to \code{TRUE}.} + +\item{plot_png_file}{String with the path to the plot file that should be written. If NULL, no file is written. Defaults to \code{NULL}.} } \value{ The data frame used to create a plot of desktop performance rate over time. diff --git a/AdWordsUtilities/man/impression_share_over_time.Rd b/AdWordsUtilities/man/impression_share_over_time.Rd index ccc2c22..63368c7 100644 --- a/AdWordsUtilities/man/impression_share_over_time.Rd +++ b/AdWordsUtilities/man/impression_share_over_time.Rd @@ -4,12 +4,14 @@ \alias{impression_share_over_time} \title{Create plot of AdWords impression share over time} \usage{ -impression_share_over_time(keywords_elog, plot = TRUE) +impression_share_over_time(keywords_elog, plot = TRUE, plot_png_file = NULL) } \arguments{ \item{keywords_elog}{A data frame containing keywords and transaction event log data.} \item{plot}{logical. If TRUE, creates a plot of the data. If false, creates no plot, Defaults to \code{TRUE}.} + +\item{plot_png_file}{String with the path to the plot file that should be written. If NULL, no file is written. Defaults to \code{NULL}.} } \value{ The data frame used to create a plot of impression share over time over time. diff --git a/AdWordsUtilities/man/keywords_campaign_performance_over_time.Rd b/AdWordsUtilities/man/keywords_campaign_performance_over_time.Rd index 03945f2..7261be6 100644 --- a/AdWordsUtilities/man/keywords_campaign_performance_over_time.Rd +++ b/AdWordsUtilities/man/keywords_campaign_performance_over_time.Rd @@ -4,12 +4,15 @@ \alias{keywords_campaign_performance_over_time} \title{Create plot of AdWords keyword performance over time, grouped by campaign} \usage{ -keywords_campaign_performance_over_time(keywords_elog, plot = TRUE) +keywords_campaign_performance_over_time(keywords_elog, plot = TRUE, + plot_png_file = NULL) } \arguments{ \item{keywords_elog}{A data frame containing keywords and transaction event log data.} \item{plot}{logical. If TRUE, creates a plot of the data. If false, creates no plot, Defaults to \code{TRUE}.} + +\item{plot_png_file}{String with the path to the plot file that should be written. If NULL, no file is written. Defaults to \code{NULL}.} } \value{ The data frame used to create a plot of performance over time. diff --git a/AdWordsUtilities/man/mobile_performance_over_time.Rd b/AdWordsUtilities/man/mobile_performance_over_time.Rd index 17e8968..101cefb 100644 --- a/AdWordsUtilities/man/mobile_performance_over_time.Rd +++ b/AdWordsUtilities/man/mobile_performance_over_time.Rd @@ -5,7 +5,7 @@ \title{Create plot of AdWords mobile performance over time} \usage{ mobile_performance_over_time(keywords_elog, keyword_filter = NULL, - campaign_filter = NULL, plot = TRUE) + campaign_filter = NULL, plot = TRUE, plot_png_file = TRUE) } \arguments{ \item{keywords_elog}{A data frame containing keywords and transaction event log data.} @@ -15,6 +15,8 @@ mobile_performance_over_time(keywords_elog, keyword_filter = NULL, \item{campaign_filter}{Optional. (e.g. "Paleo Performers") If provided, generates a data frame and plot for campaigns where the string is included in the campaign name. Default to NULL.} \item{plot}{logical. If TRUE, creates a plot of the data. If false, creates no plot, Defaults to \code{TRUE}.} + +\item{plot_png_file}{String with the path to the plot file that should be written. If NULL, no file is written. Defaults to \code{NULL}.} } \value{ The data frame used to create a plot of mobile performance over time. diff --git a/AdWordsUtilities/man/overall_performance_over_time.Rd b/AdWordsUtilities/man/overall_performance_over_time.Rd index 08acad1..fc28ce6 100644 --- a/AdWordsUtilities/man/overall_performance_over_time.Rd +++ b/AdWordsUtilities/man/overall_performance_over_time.Rd @@ -4,12 +4,15 @@ \alias{overall_performance_over_time} \title{Create plot of AdWords performance over time} \usage{ -overall_performance_over_time(keywords_elog, plot = TRUE) +overall_performance_over_time(keywords_elog, plot = TRUE, + plot_png_file = NULL) } \arguments{ \item{keywords_elog}{A data frame containing keywords and transaction event log data.} \item{plot}{logical. If TRUE, creates a plot of the data. If false, creates no plot, Defaults to \code{TRUE}.} + +\item{plot_png_file}{String with the path to the plot file that should be written. If NULL, no file is written. Defaults to \code{NULL}.} } \value{ The data frame used to create a plot of performance over time. diff --git a/BingUtilities/R/click_through_rate_over_time.r b/BingUtilities/R/click_through_rate_over_time.r index 7c4bef5..5e3070d 100644 --- a/BingUtilities/R/click_through_rate_over_time.r +++ b/BingUtilities/R/click_through_rate_over_time.r @@ -4,12 +4,13 @@ #' #' @param keywords_elog A data frame containing keywords and transaction event log data. #' @param plot logical. If TRUE, creates a plot of the data. If false, creates no plot, Defaults to \code{TRUE}. +#' @param plot_png_file String with the path to the plot file that should be written. If NULL, no file is written. Defaults to \code{NULL}. #' @return The data frame used to create a plot of clickthrough rate over time. #' @export #' @examples -#' overall_performance_over_time(elog_data_frame) +#' click_through_rate_over_time(elog_data_frame) -click_through_rate_over_time <- function(keywords_elog, plot = TRUE){ +click_through_rate_over_time <- function(keywords_elog, plot = TRUE, plot_png_file=NULL){ require(plyr) require(dplyr) keywords_weekly_conversion_metrics <- keywords_elog %>% @@ -22,8 +23,7 @@ click_through_rate_over_time <- function(keywords_elog, plot = TRUE){ if( plot ) { require(ggplot2) - plot( - ggplot( + the_plot <- ggplot( keywords_weekly_conversion_metrics %>% # Filter by a single keyword, and only include the previous 4 weeks of data. filter(week >= Sys.Date() - weeks(4), week <= Sys.Date(), keyword == "paleo meals"), @@ -32,7 +32,7 @@ click_through_rate_over_time <- function(keywords_elog, plot = TRUE){ ggtitle("Bing - Weekly CTR by Keyword") + # ylim(0, 0.30) + facet_wrap(~keyword, ncol=2) - ) + report.plot( the_plot, plot_png_file ) } return(keywords_weekly_conversion_metrics) diff --git a/BingUtilities/R/desktop_performance_over_time.r b/BingUtilities/R/desktop_performance_over_time.r index 4bcf5f9..cf3dd6d 100644 --- a/BingUtilities/R/desktop_performance_over_time.r +++ b/BingUtilities/R/desktop_performance_over_time.r @@ -5,6 +5,7 @@ #' @param keywords_elog A data frame containing keywords and transaction event log data. #' @param keyword_filter Optional. (e.g. "paleo meals") If provided, generates a data frame and plot only for the *exact* keyword provided. Default to NULL. #' @param campaign_filter Optional. (e.g. "Paleo Performers") If provided, generates a data frame and plot for campaigns where the string is included in the campaign name. Default to NULL. +#' @param plot_png_file String with the path to the plot file that should be written. If NULL, no file is written. Defaults to \code{NULL}. #' @param plot logical. If TRUE, creates a plot of the data. If false, creates no plot, Defaults to \code{TRUE}. #' @return The data frame used to create a plot of desktop performance rate over time. #' @export @@ -14,7 +15,8 @@ desktop_performance_over_time <- function( keywords_elog, keyword_filter=NULL, campaign_filter=NULL, - plot = TRUE){ + plot = TRUE, + plot_png_file=NULL){ require(plyr) require(dplyr) require(SalvatoUtilities) @@ -38,13 +40,14 @@ desktop_performance_over_time <- function( keywords_elog, if( plot ) { require(ggplot2) - plot(ggplot(devices_over_time %>% - filter(keyword %in% earnings_keywords$keyword) %>% - filter(device == "dt"), - aes(week,value,group=type,col=type,fill=type)) + - geom_line() + - ggtitle("Bing - Keyword Trends on Desktop") + - facet_wrap(~keyword + device, ncol=3)) + the_plot <- ggplot(devices_over_time %>% + filter(keyword %in% earnings_keywords$keyword) %>% + filter(device == "dt"), + aes(week,value,group=type,col=type,fill=type)) + + geom_line() + + ggtitle("Bing - Keyword Trends on Desktop") + + facet_wrap(~keyword + device, ncol=3) + report.plot(the_plot, plot_png_file) } return(devices_over_time) diff --git a/BingUtilities/R/keywords_campaign_performance_over_time.r b/BingUtilities/R/keywords_campaign_performance_over_time.r index 644566c..1966cd6 100644 --- a/BingUtilities/R/keywords_campaign_performance_over_time.r +++ b/BingUtilities/R/keywords_campaign_performance_over_time.r @@ -4,12 +4,13 @@ #' #' @param keywords_elog A data frame containing keywords and transaction event log data. #' @param plot logical. If TRUE, creates a plot of the data. If false, creates no plot, Defaults to \code{TRUE}. +#' @param plot_png_file String with the path to the plot file that should be written. If NULL, no file is written. Defaults to \code{NULL}. #' @return The data frame used to create a plot of performance over time. #' @export #' @examples #' keywords_campaign_performance_over_time(elog_data_frame) -keywords_campaign_performance_over_time <- function(keywords_elog, plot = TRUE){ +keywords_campaign_performance_over_time <- function(keywords_elog, plot = TRUE, plot_png_file=NULL){ require(plyr) require(dplyr) @@ -28,10 +29,11 @@ keywords_campaign_performance_over_time <- function(keywords_elog, plot = TRUE){ if( plot ) { require(ggplot2) - plot(ggplot(keywords_campaigns_over_time %>% filter(keyword == "paleo meals"), aes(week,value,group=type,col=type,fill=type)) + - geom_line() + - ggtitle("Bing - Keyword Trends by Campaign") + - facet_wrap(~keyword + campaign_name, ncol=2)) + the_plot <- ggplot(keywords_campaigns_over_time %>% filter(keyword == "paleo meals"), aes(week,value,group=type,col=type,fill=type)) + + geom_line() + + ggtitle("Bing - Keyword Trends by Campaign") + + facet_wrap(~keyword + campaign_name, ncol=2) + report.plot(the_plot, plot_png_file) } return(keywords_campaigns_over_time) diff --git a/BingUtilities/R/keywords_performance_over_time.r b/BingUtilities/R/keywords_performance_over_time.r index 17edf8f..0771916 100644 --- a/BingUtilities/R/keywords_performance_over_time.r +++ b/BingUtilities/R/keywords_performance_over_time.r @@ -4,12 +4,13 @@ #' #' @param keywords_elog A data frame containing keywords and transaction event log data. #' @param plot logical. If TRUE, creates a plot of the data. If false, creates no plot, Defaults to \code{TRUE}. +#' @param plot_png_file String with the path to the plot file that should be written. If NULL, no file is written. Defaults to \code{NULL}. #' @return The data frame used to create a plot of performance over time. #' @export #' @examples #' keywords_performance_over_time(elog_data_frame) -keywords_performance_over_time <- function(keywords_elog, plot = TRUE){ +keywords_performance_over_time <- function(keywords_elog, plot = TRUE, plot_png_file=NULL){ require(plyr) require(dplyr) @@ -27,10 +28,11 @@ keywords_performance_over_time <- function(keywords_elog, plot = TRUE){ if( plot ) { require(ggplot2) - plot(ggplot(keywords_over_time, aes(week,value,group=type,col=type,fill=type)) + - geom_line() + - ggtitle("Bing - Keyword Trends") + - facet_wrap(~keyword, ncol=2)) + the_plot <- ggplot(keywords_over_time, aes(week,value,group=type,col=type,fill=type)) + + geom_line() + + ggtitle("Bing - Keyword Trends") + + facet_wrap(~keyword, ncol=2) + report.plot(the_plot, plot_png_file) } return(keywords_over_time) diff --git a/BingUtilities/R/mobile_performance_over_time.r b/BingUtilities/R/mobile_performance_over_time.r index bd41993..1bd607a 100644 --- a/BingUtilities/R/mobile_performance_over_time.r +++ b/BingUtilities/R/mobile_performance_over_time.r @@ -6,6 +6,7 @@ #' @param keyword_filter Optional. (e.g. "paleo meals") If provided, generates a data frame and plot only for the *exact* keyword provided. Default to NULL. #' @param campaign_filter Optional. (e.g. "Paleo Performers") If provided, generates a data frame and plot for campaigns where the string is included in the campaign name. Default to NULL. #' @param plot logical. If TRUE, creates a plot of the data. If false, creates no plot, Defaults to \code{TRUE}. +#' @param plot_png_file String with the path to the plot file that should be written. If NULL, no file is written. Defaults to \code{NULL}. #' @return The data frame used to create a plot of mobile performance over time. #' @export #' @examples @@ -14,7 +15,8 @@ mobile_performance_over_time <- function( keywords_elog, keyword_filter=NULL, campaign_filter=NULL, - plot = TRUE){ + plot = TRUE, + plot_png_file=NULL){ require(plyr) require(dplyr) require(SalvatoUtilities) @@ -38,14 +40,15 @@ mobile_performance_over_time <- function( keywords_elog, if( plot ) { require(ggplot2) - plot(ggplot(devices_over_time %>% + the_plot <- ggplot(devices_over_time %>% filter(keyword %in% earnings_keywords$keyword) %>% filter(device == "mb"), aes(week,value,group=type,col=type,fill=type)) + geom_line() + ggtitle("Bing - Keyword Trends on Mobile") + ylim(-1000,1500) + - facet_wrap(~keyword + device, ncol=3)) + facet_wrap(~keyword + device, ncol=3) + report.plot( the_plot, plot_png_file ) } return(devices_over_time) diff --git a/BingUtilities/R/overall_performance_over_time.r b/BingUtilities/R/overall_performance_over_time.r index 441f74b..4fda6df 100644 --- a/BingUtilities/R/overall_performance_over_time.r +++ b/BingUtilities/R/overall_performance_over_time.r @@ -3,13 +3,14 @@ #' Takes in a Bing event log and processes all summary data #' #' @param keywords_elog A data frame containing keywords and transaction event log data. -#' @return plot logical. If TRUE, creates a plot of the data. If false, creates no plot, Defaults to \code{TRUE}. +#' @param plot logical. If TRUE, creates a plot of the data. If false, creates no plot, Defaults to \code{TRUE}. +#' @param plot_png_file String with the path to the plot file that should be written. If NULL, no file is written. Defaults to \code{NULL}. #' @return The data frame used to create a plot of performance over time. #' @export #' @examples #' overall_performance_over_time(elog_data_frame) -overall_performance_over_time <- function(keywords_elog, plot = TRUE){ +overall_performance_over_time <- function(keywords_elog, plot = TRUE, plot_png_file=NULL){ require(plyr) require(dplyr) all_keyword_ROAS_over_time <- keywords_elog %>% @@ -23,10 +24,10 @@ overall_performance_over_time <- function(keywords_elog, plot = TRUE){ if( plot ) { require(ggplot2) - plot(ggplot(all_keyword_ROAS_over_time, + the_plot <- ggplot(all_keyword_ROAS_over_time, aes(week,value,group=type,col=type,fill=type)) + geom_line() - ) + report.plot( the_plot, plot_png_file) } return(all_keyword_ROAS_over_time) diff --git a/BingUtilities/man/click_through_rate_over_time.Rd b/BingUtilities/man/click_through_rate_over_time.Rd index dcb314f..793d4f3 100644 --- a/BingUtilities/man/click_through_rate_over_time.Rd +++ b/BingUtilities/man/click_through_rate_over_time.Rd @@ -4,12 +4,15 @@ \alias{click_through_rate_over_time} \title{Create plot of Bing click through rate over time} \usage{ -click_through_rate_over_time(keywords_elog, plot = TRUE) +click_through_rate_over_time(keywords_elog, plot = TRUE, + plot_png_file = NULL) } \arguments{ \item{keywords_elog}{A data frame containing keywords and transaction event log data.} \item{plot}{logical. If TRUE, creates a plot of the data. If false, creates no plot, Defaults to \code{TRUE}.} + +\item{plot_png_file}{String with the path to the plot file that should be written. If NULL, no file is written. Defaults to \code{NULL}.} } \value{ The data frame used to create a plot of clickthrough rate over time. @@ -18,6 +21,6 @@ The data frame used to create a plot of clickthrough rate over time. Takes in a Bing event log and processes click through rate over time. } \examples{ -overall_performance_over_time(elog_data_frame) +click_through_rate_over_time(elog_data_frame) } diff --git a/BingUtilities/man/desktop_performance_over_time.Rd b/BingUtilities/man/desktop_performance_over_time.Rd index 8eacdfd..a379a19 100644 --- a/BingUtilities/man/desktop_performance_over_time.Rd +++ b/BingUtilities/man/desktop_performance_over_time.Rd @@ -15,6 +15,8 @@ desktop_performance_over_time(keywords_elog, keyword_filter = NULL, \item{campaign_filter}{Optional. (e.g. "Paleo Performers") If provided, generates a data frame and plot for campaigns where the string is included in the campaign name. Default to NULL.} \item{plot}{logical. If TRUE, creates a plot of the data. If false, creates no plot, Defaults to \code{TRUE}.} + +\item{plot_png_file}{String with the path to the plot file that should be written. If NULL, no file is written. Defaults to \code{NULL}.} } \value{ The data frame used to create a plot of desktop performance rate over time. diff --git a/BingUtilities/man/keywords_campaign_performance_over_time.Rd b/BingUtilities/man/keywords_campaign_performance_over_time.Rd index 38753e7..5287c36 100644 --- a/BingUtilities/man/keywords_campaign_performance_over_time.Rd +++ b/BingUtilities/man/keywords_campaign_performance_over_time.Rd @@ -4,12 +4,15 @@ \alias{keywords_campaign_performance_over_time} \title{Create plot of Bing keyword performance over time, grouped by campaign} \usage{ -keywords_campaign_performance_over_time(keywords_elog, plot = TRUE) +keywords_campaign_performance_over_time(keywords_elog, plot = TRUE, + plot_png_file = NULL) } \arguments{ \item{keywords_elog}{A data frame containing keywords and transaction event log data.} \item{plot}{logical. If TRUE, creates a plot of the data. If false, creates no plot, Defaults to \code{TRUE}.} + +\item{plot_png_file}{String with the path to the plot file that should be written. If NULL, no file is written. Defaults to \code{NULL}.} } \value{ The data frame used to create a plot of performance over time. diff --git a/BingUtilities/man/keywords_performance_over_time.Rd b/BingUtilities/man/keywords_performance_over_time.Rd index 099752d..603106e 100644 --- a/BingUtilities/man/keywords_performance_over_time.Rd +++ b/BingUtilities/man/keywords_performance_over_time.Rd @@ -4,12 +4,15 @@ \alias{keywords_performance_over_time} \title{Create plot of Bing keyword performance over time} \usage{ -keywords_performance_over_time(keywords_elog, plot = TRUE) +keywords_performance_over_time(keywords_elog, plot = TRUE, + plot_png_file = NULL) } \arguments{ \item{keywords_elog}{A data frame containing keywords and transaction event log data.} \item{plot}{logical. If TRUE, creates a plot of the data. If false, creates no plot, Defaults to \code{TRUE}.} + +\item{plot_png_file}{String with the path to the plot file that should be written. If NULL, no file is written. Defaults to \code{NULL}.} } \value{ The data frame used to create a plot of performance over time. diff --git a/BingUtilities/man/mobile_performance_over_time.Rd b/BingUtilities/man/mobile_performance_over_time.Rd index 2a16d2d..68b3c77 100644 --- a/BingUtilities/man/mobile_performance_over_time.Rd +++ b/BingUtilities/man/mobile_performance_over_time.Rd @@ -5,7 +5,7 @@ \title{Create plot of Bing mobile performance over time} \usage{ mobile_performance_over_time(keywords_elog, keyword_filter = NULL, - campaign_filter = NULL, plot = TRUE) + campaign_filter = NULL, plot = TRUE, plot_png_file = NULL) } \arguments{ \item{keywords_elog}{A data frame containing keywords and transaction event log data.} @@ -15,6 +15,8 @@ mobile_performance_over_time(keywords_elog, keyword_filter = NULL, \item{campaign_filter}{Optional. (e.g. "Paleo Performers") If provided, generates a data frame and plot for campaigns where the string is included in the campaign name. Default to NULL.} \item{plot}{logical. If TRUE, creates a plot of the data. If false, creates no plot, Defaults to \code{TRUE}.} + +\item{plot_png_file}{String with the path to the plot file that should be written. If NULL, no file is written. Defaults to \code{NULL}.} } \value{ The data frame used to create a plot of mobile performance over time. diff --git a/BingUtilities/man/overall_performance_over_time.Rd b/BingUtilities/man/overall_performance_over_time.Rd index 2adcc96..a1d7976 100644 --- a/BingUtilities/man/overall_performance_over_time.Rd +++ b/BingUtilities/man/overall_performance_over_time.Rd @@ -4,14 +4,17 @@ \alias{overall_performance_over_time} \title{Create plot of Bing performance over time} \usage{ -overall_performance_over_time(keywords_elog, plot = TRUE) +overall_performance_over_time(keywords_elog, plot = TRUE, + plot_png_file = NULL) } \arguments{ \item{keywords_elog}{A data frame containing keywords and transaction event log data.} + +\item{plot}{logical. If TRUE, creates a plot of the data. If false, creates no plot, Defaults to \code{TRUE}.} + +\item{plot_png_file}{String with the path to the plot file that should be written. If NULL, no file is written. Defaults to \code{NULL}.} } \value{ -plot logical. If TRUE, creates a plot of the data. If false, creates no plot, Defaults to \code{TRUE}. - The data frame used to create a plot of performance over time. } \description{ diff --git a/PowerSupplyUtilities/R/orders_per_week.r b/PowerSupplyUtilities/R/orders_per_week.r index 9e54cd1..9119ecf 100644 --- a/PowerSupplyUtilities/R/orders_per_week.r +++ b/PowerSupplyUtilities/R/orders_per_week.r @@ -6,6 +6,7 @@ #' @param keyword_filter Optional. (e.g. "paleo meals") If provided, generates a data frame and plot only for the *exact* keyword provided. Default to NULL. #' @param campaign_filter Optional. (e.g. "Paleo Performers") If provided, generates a data frame and plot for campaigns where the string is included in the campaign name. Default to NULL. #' @param plot logical. If TRUE, creates a plot of the data. If false, creates no plot, Defaults to \code{TRUE}. +#' @param plot_png_file String with the path to the plot file that should be written. If NULL, no file is written. Defaults to \code{NULL}. #' @return The data frame used to create a plot of performance over time. #' @export #' @examples @@ -14,7 +15,8 @@ orders_per_week <- function(keywords_elog, keyword_filter=NULL, campaign_filter=NULL, - plot = TRUE){ + plot = TRUE, + plot_png_file=NULL){ require(plyr) require(dplyr) if( !is.null(keyword_filter) ) { @@ -33,11 +35,13 @@ orders_per_week <- function(keywords_elog, if( plot ) { require(ggplot2) - plot( ggplot( num_orders_per_week ) + + the_plot <- ggplot( num_orders_per_week ) + aes(week,num_orders,group=campaign_name,col=campaign_name,fill=campaign_name) + geom_line() + ylim(0,max(num_orders_per_week$num_orders))+ - facet_wrap(~campaign_name, ncol=2)) + facet_wrap(~campaign_name, ncol=2) + + report.plot( the_plot, plot_png_file) } return(num_orders_per_week) diff --git a/PowerSupplyUtilities/R/paleo_cohort_views.r b/PowerSupplyUtilities/R/paleo_cohort_views.r index 43f6077..3055dc5 100644 --- a/PowerSupplyUtilities/R/paleo_cohort_views.r +++ b/PowerSupplyUtilities/R/paleo_cohort_views.r @@ -8,6 +8,10 @@ #' paleo_cohort_views(keywords_elog) paleo_cohort_views <- function(keywords_elog) { + elog_name <- deparse(substitute(keywords_elog)) #gets variable name as string + file_prefix <- if(grepl("adwords",elog_name)) "adwords" else "bing" + + paleo_meals_cohort <- filter(keywords_elog,keyword == "paleo meals") ##assign ordinal number to weeks @@ -132,8 +136,7 @@ paleo_cohort_views <- function(keywords_elog) { ymax <- ceiling(signif(max(paleo_meals_cohorts_total_ROI$value.x,paleo_meals_cohorts_total_ROI$value.y),2)) ymin <- floor(signif(min(paleo_meals_cohorts_total_ROI$value.x,paleo_meals_cohorts_total_ROI$value.y),2)) - plot( - ggplot( + plot1 <- ggplot( paleo_meals_cohorts_total_ROI, aes(x=cohort_week,y=value.x, fill=type.x)) + geom_bar(stat="identity", position="identity") + @@ -143,19 +146,19 @@ paleo_cohort_views <- function(keywords_elog) { scale_y_continuous(breaks=seq(ymin,ymax,500),labels=scales::dollar) + scale_fill_manual(values=c("springgreen4","red2")) + guides(fill=guide_legend(title=NULL)) + - labs(title="Contribution, Cost, and ROI by Cohort Week",x="Cohort Week",y="") - ) + labs(title="Contribution, Cost, and ROI by Cohort Week",x="Cohort Week",y="") + report.plot( plot1, file=paste0("output/",file_prefix,"_cohorts_breakdown.png")) + ##Weekly Cohort Plot 2: Number of weeks it took each cohort to break even max_be <- max(paleo_meals_cohort_breakeven$weeks_until_breakeven,na.rm=TRUE) - plot( - ggplot( - paleo_meals_cohort_breakeven, + + plot2 <- ggplot(paleo_meals_cohort_breakeven, aes(x=cohort_week,y=weeks_until_breakeven)) + geom_bar(stat="identity", position="dodge") + scale_x_continuous(breaks=seq(1,max_cw,1)) + scale_y_continuous(breaks=seq(0,max_be,1)) + labs(title="Weeks to Break Even per Cohort Week",x="Cohort Week",y="Number of Weeks") - ) + report.plot( plot2, file=paste0("output/",file_prefix,"_cohorts_time_to_break_even.png")) } \ No newline at end of file diff --git a/PowerSupplyUtilities/R/search_engine_marketing_report.r b/PowerSupplyUtilities/R/search_engine_marketing_report.r index 71c6375..5730837 100644 --- a/PowerSupplyUtilities/R/search_engine_marketing_report.r +++ b/PowerSupplyUtilities/R/search_engine_marketing_report.r @@ -16,20 +16,22 @@ search_engine_marketing_report <- function( adwords_keywords_elog=NULL, if(!is.null(adwords_keywords_elog)) { require(AdWordsUtilities) PowerSupplyUtilities::user_overview(adwords_keywords_elog) - AdWordsUtilities::keywords_campaign_device_matchtype_report(adwords_keywords_elog) - AdWordsUtilities::impression_share_over_time(adwords_keywords_elog) - AdWordsUtilities::click_through_rate_over_time(adwords_keywords_elog) - AdWordsUtilities::overall_performance_over_time(adwords_keywords_elog, plot = TRUE) - AdWordsUtilities::contribution_per_click_report(adwords_keywords_elog) + AdWordsUtilities::keywords_campaign_device_matchtype_report(adwords_keywords_elog, file="output/adwords_keyword_campaign_device_matchtype_report.csv") + AdWordsUtilities::impression_share_over_time(adwords_keywords_elog, plot_png_file="output/adwords_impression_share_over_time.png") + AdWordsUtilities::click_through_rate_over_time(adwords_keywords_elog, plot_png_file="output/adwords_click_through_rate_over_time.png") + AdWordsUtilities::overall_performance_over_time(adwords_keywords_elog, plot_png_file="output/adwords_overall_performance_over_time.png") + AdWordsUtilities::contribution_per_click_report(adwords_keywords_elog, file="output/adwords_contribution_per_click_report.csv") PowerSupplyUtilities::orders_per_week(adwords_keywords_elog, - keyword_filter="paleo meals", - campaign_filter="Paleo Performers") + keyword_filter="paleo meals", + campaign_filter="Paleo Performers", + plot_png_file="output/adwords_orders_per_week.png") PowerSupplyUtilities::paleo_cohort_views(adwords_keywords_elog) - adwords_customers_per_month_report <- PowerSupplyUtilities::customers_per_month_report(adwords_keywords_elog, file="adwords_customers_per_month.csv") - AdWordsUtilities::mobile_performance_over_time(adwords_keywords_elog, keyword_filter="paleo meals") - AdWordsUtilities::desktop_performance_over_time(adwords_keywords_elog, keyword_filter="paleo meals") - AdWordsUtilities::keywords_performance_over_time(adwords_keywords_elog) - AdWordsUtilities::keywords_campaign_performance_over_time(adwords_keywords_elog) + adwords_customers_per_month_report <- PowerSupplyUtilities::customers_per_month_report( adwords_keywords_elog, + file="output/adwords_customers_per_month.csv") + AdWordsUtilities::mobile_performance_over_time(adwords_keywords_elog, keyword_filter="paleo meals", plot_png_file="output/adwords_mobile_performance_over_time.png") + AdWordsUtilities::desktop_performance_over_time(adwords_keywords_elog, keyword_filter="paleo meals", plot_png_file="output/adwords_desktop_performance_over_time.png") + AdWordsUtilities::keywords_performance_over_time(adwords_keywords_elog, plot_png_file="output/adwords_keywords_performance_over_time.png") + AdWordsUtilities::keywords_campaign_performance_over_time(adwords_keywords_elog, plot_png_file="output/adwords_keywords_campaign_performance_over_time.png") # Should this be made into a report function too? # adwords_keywords_elog %>% AdWordsUtilities::summarize_elog() } @@ -37,28 +39,29 @@ search_engine_marketing_report <- function( adwords_keywords_elog=NULL, if(!is.null(bing_keywords_elog)) { require(BingUtilities) PowerSupplyUtilities::user_overview(bing_keywords_elog) - BingUtilities::keywords_campaign_device_matchtype_report(bing_keywords_elog) - BingUtilities::click_through_rate_over_time(bing_keywords_elog) - BingUtilities::overall_performance_over_time(bing_keywords_elog, plot = TRUE) - BingUtilities::contribution_per_click_report(bing_keywords_elog) - PowerSupplyUtilities::orders_per_week(bing_keywords_elog, keyword_filter="paleo meals") + BingUtilities::keywords_campaign_device_matchtype_report(bing_keywords_elog, file="output/bing_keywords_campaign_device_matchtype_report.csv") + BingUtilities::click_through_rate_over_time(bing_keywords_elog, plot_png_file="output/bing_click_through_rate_over_time.png") + BingUtilities::overall_performance_over_time(bing_keywords_elog, plot_png_file="output/bing_overall_performance_over_time.png") + BingUtilities::contribution_per_click_report(bing_keywords_elog, file="output/bing_contribution_per_click_report.csv") + PowerSupplyUtilities::orders_per_week(bing_keywords_elog, keyword_filter="paleo meals", plot_png_file="output/bing_orders_per_week.png") PowerSupplyUtilities::paleo_cohort_views(bing_keywords_elog) - bing_customers_per_month_report <- PowerSupplyUtilities::customers_per_month_report(bing_keywords_elog, file="bing_customers_per_month.csv") - BingUtilities::mobile_performance_over_time(bing_keywords_elog, keyword_filter="paleo meals") - BingUtilities::desktop_performance_over_time(bing_keywords_elog, keyword_filter="paleo meals") - BingUtilities::keywords_performance_over_time(bing_keywords_elog) - BingUtilities::keywords_campaign_performance_over_time(bing_keywords_elog) + bing_customers_per_month_report <- PowerSupplyUtilities::customers_per_month_report(bing_keywords_elog, file="output/bing_customers_per_month.csv") + BingUtilities::mobile_performance_over_time(bing_keywords_elog, keyword_filter="paleo meals", plot_png_file="output/bing_mobile_performance_over_time.png") + BingUtilities::desktop_performance_over_time(bing_keywords_elog, keyword_filter="paleo meals", plot_png_file="output/bing_desktop_performance_over_time.png") + BingUtilities::keywords_performance_over_time(bing_keywords_elog, plot_png_file="output/bing_keywords_performance_over_time.png") + BingUtilities::keywords_campaign_performance_over_time(bing_keywords_elog, plot_png_file="output/bing_keywords_campaign_performance_over_time.png") # Should this be made into a report function too? # bing_keywords_elog %>% BingUtilities::summarize_elog() } if(!is.null(gdn_elog)) { require(AdWordsUtilities) - AdWordsUtilities::overall_performance_over_time(gdn_elog) - AdWordsUtilities::desktop_gdn_performance_over_time(gdn_elog) - AdWordsUtilities::mobile_gdn_performance_over_time(gdn_elog) + AdWordsUtilities::overall_performance_over_time(gdn_elog, plot_png_file="output/gdn_overall_performance_over_time.png") + AdWordsUtilities::desktop_gdn_performance_over_time(gdn_elog, plot_png_file="output/gdn_desktop_performance_over_time.png") + AdWordsUtilities::mobile_gdn_performance_over_time(gdn_elog,, plot_png_file="output/gdn_mobile_performance_over_time.png") PowerSupplyUtilities::orders_per_week(gdn_elog, - campaign_filter="Rmktg") + campaign_filter="Rmktg", + plot_png_file="output/gdn_orders_per_week.png") } @@ -70,7 +73,7 @@ search_engine_marketing_report <- function( adwords_keywords_elog=NULL, suffixes=c(".adwords",".bing")) %>% mutate_each(funs(ifelse(is.na(.),0,.))) %>% mutate(total_acquisitions=num_acquisitions.adwords+num_acquisitions.bing) - write.excel.csv(total_customers_per_month_report) + write.excel.csv(total_customers_per_month_report, file="output/total_customers_per_month_report.csv") } diff --git a/SalvatoUtilities/NAMESPACE b/SalvatoUtilities/NAMESPACE index 4efc3aa..8de21d6 100644 --- a/SalvatoUtilities/NAMESPACE +++ b/SalvatoUtilities/NAMESPACE @@ -3,5 +3,6 @@ export(as.week) export(date_filter) export(detach_all_packages) +export(report.plot) export(string_from_file) export(write.excel.csv) diff --git a/overview_report.r b/overview_report.r index 4c07030..6ecd9c8 100644 --- a/overview_report.r +++ b/overview_report.r @@ -48,4 +48,5 @@ gdn_elog <- create_google_display_event_log(from, to) ###################################### CREATE AdWords Plots and CSVs ############################################## PowerSupplyUtilities::search_engine_marketing_report( adwords_keywords_elog, bing_keywords_elog, - gdn_elog) \ No newline at end of file + gdn_elog) + From 8fbbeeaf6dc23164660ad95ffa9fca4d6c34fa56 Mon Sep 17 00:00:00 2001 From: Chris Salvato Date: Mon, 13 Jun 2016 09:32:00 -0400 Subject: [PATCH 5/5] Create file output for all plots that are generated --- SalvatoUtilities/R/report.plot.r | 46 +++++++++++++++++++++++++++++ SalvatoUtilities/man/report.plot.Rd | 32 ++++++++++++++++++++ 2 files changed, 78 insertions(+) create mode 100644 SalvatoUtilities/R/report.plot.r create mode 100644 SalvatoUtilities/man/report.plot.Rd diff --git a/SalvatoUtilities/R/report.plot.r b/SalvatoUtilities/R/report.plot.r new file mode 100644 index 0000000..45f4e9f --- /dev/null +++ b/SalvatoUtilities/R/report.plot.r @@ -0,0 +1,46 @@ +#' Report Plot +#' +#' Creates a plot for an exported report. +#' Writes a ggplot object to a plot using plot() or writes the plot to a PNG file. +#' +#' @param ggplot_object ggplot object to be plotted. +#' @param file (optional) File name for the file to be saved. If not supplied +#' then the data frame's name is used. Note, ".csv" is appended automatically. +#' @export +#' @examples +#' test <- ggplot( +#' keywords_weekly_conversion_metrics, +#' aes(x=week, y=est_search_impression_share, fill=campaign_name)) + +#' geom_bar(stat="identity", position="dodge") + +#' ggtitle("AdWords - Weekly Impression Share by Geo") + +#' ylim(0, 1) + +#' facet_wrap(~keyword, ncol=2) +#' ) +#' report.plot(test, "example.png") # Writes to file "example.png" +#' report.plot(test, "") # Writes to file test.png +#' report.plot(test, NULL) # Plots without writing to file. + +report.plot <- function(ggplot_object, file=""){ + # If the file name is not specified, use the data frame variable name. + if( file == "" ) { + file <- deparse(substitute(data_frame)) #gets variable name as string + } + + # If doesn't have .png extension in the name, add it. + if ( !grepl("\\.png$", file) ) { + file <- paste0(file,".png") + } + + if( !is.null(file) ) { + require(SalvatoUtilities) + png( filename = file, + width = 1280, + height = 800) + plot( ggplot_object ) + dev.off() + } else { + plot( ggplot_object ) + } + + +} \ No newline at end of file diff --git a/SalvatoUtilities/man/report.plot.Rd b/SalvatoUtilities/man/report.plot.Rd new file mode 100644 index 0000000..56e84d4 --- /dev/null +++ b/SalvatoUtilities/man/report.plot.Rd @@ -0,0 +1,32 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/report.plot.r +\name{report.plot} +\alias{report.plot} +\title{Report Plot} +\usage{ +report.plot(ggplot_object, file = "") +} +\arguments{ +\item{ggplot_object}{ggplot object to be plotted.} + +\item{file}{(optional) File name for the file to be saved. If not supplied +then the data frame's name is used. Note, ".csv" is appended automatically.} +} +\description{ +Creates a plot for an exported report. +Writes a ggplot object to a plot using plot() or writes the plot to a PNG file. +} +\examples{ +test <- ggplot( + keywords_weekly_conversion_metrics, + aes(x=week, y=est_search_impression_share, fill=campaign_name)) + + geom_bar(stat="identity", position="dodge") + + ggtitle("AdWords - Weekly Impression Share by Geo") + + ylim(0, 1) + + facet_wrap(~keyword, ncol=2) + ) +report.plot(test, "example.png") # Writes to file "example.png" +report.plot(test, "") # Writes to file test.png +report.plot(test, NULL) # Plots without writing to file. +} +