forked from CrumpLab/LabJournalWebsite
-
Notifications
You must be signed in to change notification settings - Fork 1
/
YearToDate.Rmd
138 lines (126 loc) · 5.48 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
---
title: "Year-To-Date"
output: html_document
date: "Last updated: 6/30/2021"
---
```{css, echo=FALSE}
h1 {
text-align: center;
}
```
```{r setup, include=FALSE}
knitr::opts_knit$set(echo=FALSE, warning=FALSE, message=FALSE)
data <- read.csv('May2021TrackingData.csv')
#load pre-written evaluation functions
source("monthlyreport_functions.R")
dataReformatted <- reformat_googlesheet(data)
```
# Year-to-Date: May 2021
```{r YTD Hit Type, echo=FALSE, warning=FALSE, message=FALSE}
## Hit Type
library('openair')
YTDdata2020 <- dataReformatted[which(dataReformatted$month %in% c("January", "February", "March", "April", "May") & dataReformatted$year=="2020"),]
YTDdata2021 <- dataReformatted[which(dataReformatted$month %in% c("January", "February", "March", "April", "May") & dataReformatted$year=="2021"),]
previousYear(YTDdata2021, YTDdata2020)
```
## TV
```{r, TV Goals, echo=FALSE, warning=FALSE, message=FALSE}
#subset 2021 data
data2021 <-dataReformatted[which(dataReformatted$year==2021),]
#one source per row
library('tidyr')
data2021.sepsource <- separate_rows(data2021, source, sep = ",")
data2021.sepsource$source <- trimws(data2021.sepsource$source, which='both')
data2021.sepsource <- subset(data2021.sepsource, source=="CC"|source=="CM"|source=="CMN")
#replace NAs in tv column with 0s
data2021.sepsource$tv[is.na(data2021.sepsource$tv)] <- 0
#summarize tv by month
library("dplyr")
tvbymonth <- data2021.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(396, 792, 1188, 1584, 1980, 2376, 2772, 3168, 3564, 3960, 4356, 4752)
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=="May"), aes(label = 2089), 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
data2021 <-dataReformatted[which(dataReformatted$year==2021),]
#one source per row
data2021.sepsource <- separate_rows(data2021, source, sep = ",")
data2021.sepsource <- subset(data2021.sepsource, source=="CC"|source=="CM"|source=="CMN")
#summarize articles by month
library("dplyr")
articlesbymonth <- data2021.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=="May"), aes(label = value), nudge_x = 0.5, nudge_y = 50, color="black") +
scale_x_discrete(limits = month.name)
articlesgoalschart
```