Skip to content

Commit

Permalink
Merge pull request #23 from powersupplyhq/create_png_of_plots_by_default
Browse files Browse the repository at this point in the history
Create png of plots by default
  • Loading branch information
csalvato authored Jun 13, 2016
2 parents f56e4d6 + 8fbbeea commit 26447b4
Show file tree
Hide file tree
Showing 37 changed files with 287 additions and 132 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ jdbc_*.txt
adwords_credentials.txt
*.yml
temp_*.txt
*.yml
*.yml
output/*
9 changes: 5 additions & 4 deletions AdWordsUtilities/R/click_through_rate_over_time.r
Original file line number Diff line number Diff line change
Expand Up @@ -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 %>%
Expand All @@ -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"),
Expand All @@ -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)
Expand Down
9 changes: 6 additions & 3 deletions AdWordsUtilities/R/desktop_gdn_performance_over_time.r
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand All @@ -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)
Expand Down
19 changes: 11 additions & 8 deletions AdWordsUtilities/R/desktop_performance_over_time.r
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand All @@ -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)
Expand Down
26 changes: 14 additions & 12 deletions AdWordsUtilities/R/impression_share_over_time.r
Original file line number Diff line number Diff line change
Expand Up @@ -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 %>%
Expand All @@ -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)
Expand Down
10 changes: 7 additions & 3 deletions AdWordsUtilities/R/keywords_campaign_performance_over_time.r
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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)
Expand Down
8 changes: 5 additions & 3 deletions AdWordsUtilities/R/keywords_performance_over_time.r
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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)
Expand Down
9 changes: 6 additions & 3 deletions AdWordsUtilities/R/mobile_gdn_performance_over_time.r
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand All @@ -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)
Expand Down
18 changes: 11 additions & 7 deletions AdWordsUtilities/R/mobile_performance_over_time.r
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand All @@ -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)
Expand Down
7 changes: 4 additions & 3 deletions AdWordsUtilities/R/overall_performance_over_time.r
Original file line number Diff line number Diff line change
Expand Up @@ -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 %>%
Expand All @@ -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)
Expand Down
1 change: 0 additions & 1 deletion AdWordsUtilities/R/raw_keyword_performance_data.r
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
5 changes: 4 additions & 1 deletion AdWordsUtilities/man/click_through_rate_over_time.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion AdWordsUtilities/man/desktop_performance_over_time.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion AdWordsUtilities/man/impression_share_over_time.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 26447b4

Please sign in to comment.