forked from lisasheridan/CMTracking
-
Notifications
You must be signed in to change notification settings - Fork 0
/
YearToDate.Rmd
144 lines (128 loc) · 5.52 KB
/
YearToDate.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
---
title: "Year-To-Date"
output: html_document
date: "Last updated: 11/14/2022"
---
```{css, echo=FALSE}
h1 {
text-align: center;
}
```
```{r setup, include=FALSE}
knitr::opts_knit$set(echo=FALSE, warning=FALSE, message=FALSE)
#load pre-written evaluation functions
source("monthlyreport_functions.R")
data <- read.csv('September2022TrackingData.csv')
dataReformatted <- reformat_googlesheet(data)
```
# Year-to-Date: September 2022
```{r YTD Hit Type, echo=FALSE, warning=FALSE, message=FALSE}
## Hit Type
library('openair')
YTDdata2021 <- dataReformatted[which(dataReformatted$month %in% c("September") & dataReformatted$year=="2021"),]
YTDdata2022 <- dataReformatted[which(dataReformatted$month %in% c("September") & dataReformatted$year=="2022"),]
previousYear(YTDdata2022, YTDdata2021)
```
\*Facebook and Other Social (Instagram and Youtube) tracking stopped June 2021.
***
## TV
```{r, TV Goals, echo=FALSE, warning=FALSE, message=FALSE}
#subset 2021 data
data2022 <-dataReformatted[which(dataReformatted$year==2022),]
#one source per row
library('tidyr')
data2022.sepsource <- separate_rows(data2022, source, sep = ",")
data2022.sepsource$source <- trimws(data2022.sepsource$source, which='both')
data2022.sepsource <- subset(data2022.sepsource, source=="CC"|source=="CM"|source=="CMN")
#replace NAs in tv column with 0s
data2022.sepsource$tv[is.na(data2022.sepsource$tv)] <- 0
#summarize tv by month
library("dplyr")
tvbymonth <- data2022.sepsource %>%
group_by(month) %>%
summarise(tv=sum(tv))
#add 20% to tv
tvbymonth$tv <- round(tvbymonth$tv*1.2, digits=0)
#order data by month
library('dplyr')
tvbymonth <- tvbymonth %>% arrange(match(month, month.name))
#add column for cumulative sum of tv airings
tvbymonth$cumulative.tv <- cumsum(tvbymonth$tv)
tvbymonth <- as.data.frame(tvbymonth)
#tv goals
tv.goals <- c(541, 1082, 1623, 2164, 2705, 3246, 3787, 4328, 4869, 5410, 5951, 6500)
month <- month.name
tvgoals.bymonth <- data.frame(month, tv.goals)
#merge hits and goals
tvgoalsandhits <- merge(tvbymonth, tvgoals.bymonth, by="month", all.y = TRUE)
#remove tv column
tvgoalsandhits <- subset(tvgoalsandhits, select=-tv)
#reorder columns
tvgoalsandhits <- tvgoalsandhits[,c(1,3,2)]
names(tvgoalsandhits) <- c("Month", "Goals", "Airings")
#melt dataframe
library("reshape2")
melted.tvgoalsandhits <- melt(tvgoalsandhits)
#make variable a factor
melted.tvgoalsandhits$variable <- factor(melted.tvgoalsandhits$variable, levels = c("Goals", "Airings"))
melted.tvgoalsandhits$variable <- sort(melted.tvgoalsandhits$variable)
#plot chart
library("ggplot2")
tvgoalschart <- ggplot(melted.tvgoalsandhits, aes(Month, value, group=variable, colour=variable, linetype=variable)) +
theme(axis.text.x = element_text(angle=45, vjust=0.7)) +
geom_line(aes(color=variable)) +
scale_linetype_manual(values=c("dashed", "solid")) +
labs(y="TV Airings", x="") +
theme(legend.title = element_blank())+
geom_text(data=melted.tvgoalsandhits %>% filter(variable=="Airings" & Month=="February"), aes(label = 590), nudge_x = 0.4, nudge_y = 50, color="black") +
scale_x_discrete(limits = month.name)
tvgoalschart
```
## Articles
```{r, Article Goals, echo=FALSE, warning=FALSE, message=FALSE}
#subset 2021 data
data2022 <-dataReformatted[which(dataReformatted$year==2022),]
#one source per row
data2022.sepsource <- separate_rows(data2022, source, sep = ",")
data2022.sepsource <- subset(data2022.sepsource, source=="CC"|source=="CM"|source=="CMN")
#summarize articles by month
library("dplyr")
articlesbymonth <- data2022.sepsource %>%
group_by(month) %>%
summarise(articles=sum(online.article))
#order data by month
library("dplyr")
articlesbymonth <- articlesbymonth %>% arrange(match(month, month.name))
#c("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December")
#add column for cumulative sum of articles
articlesbymonth$cumulative.articles <- cumsum(articlesbymonth$articles)
articlesbymonth <- as.data.frame(articlesbymonth)
#articles goals
articles.goals <- c(317, 634, 951, 1268, 1585, 1902, 2219, 2536, 2853, 3170, 3487, 3804)
month <- month.name
articlesgoals.bymonth <- data.frame(month, articles.goals)
#merge hits and goals
articlesgoalsandhits <- merge(articlesbymonth, articlesgoals.bymonth, by="month", all.y = TRUE)
#remove articles column
articlesgoalsandhits <- subset(articlesgoalsandhits, select=-articles)
#reorder columns
articlesgoalsandhits <- articlesgoalsandhits[,c(1,3,2)]
names(articlesgoalsandhits) <- c("Month", "Goals", "Articles")
#melt dataframe
library("reshape2")
melted.articlesgoalsandhits <- melt(articlesgoalsandhits)
#make variable a factor
melted.articlesgoalsandhits$variable <- factor(melted.articlesgoalsandhits$variable, levels = c("Goals", "Articles"))
melted.articlesgoalsandhits$variable <- sort(melted.articlesgoalsandhits$variable)
#plot chart
library("ggplot2")
articlesgoalschart <- ggplot(melted.articlesgoalsandhits, aes(Month, value, group=variable, colour=variable, linetype=variable)) +
theme(axis.text.x = element_text(angle=45, vjust=0.7)) +
geom_line(aes(color=variable)) +
scale_linetype_manual(values=c("dashed", "solid")) +
labs(y="Articles", x="") +
theme(legend.title = element_blank()) +
geom_text(data=melted.articlesgoalsandhits %>% filter(variable=="Articles" & Month=="January"), aes(label = 268), nudge_x = 0.5, nudge_y = 50, color="black") +
scale_x_discrete(limits = month.name)
articlesgoalschart
```