-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathviews_heatmap.rmd
More file actions
122 lines (90 loc) · 5.25 KB
/
views_heatmap.rmd
File metadata and controls
122 lines (90 loc) · 5.25 KB
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
---
title: "DataRes Visualizations"
author: "Aaron Lee"
date: "October 23, 2019"
output: html_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
```{r message = FALSE}
library(readr)
library(dplyr)
library(ggplot2)
library(lubridate)
library(scales)
library(tidyverse)
library(RColorBrewer)
```
```{r message = FALSE}
df <- read_csv("USvideos.csv")
data <- mutate(df, formatted_trending_date = ydm(trending_date), publish_date = as.Date(format(df$publish_time, "%Y-%m-%d")))
data_frame <- mutate(data, trending_month = month(formatted_trending_date), trending_day = day(formatted_trending_date), trending_year = year(formatted_trending_date), publish_month = month(publish_time), publish_day = day(publish_time), publish_year = year(publish_time))
youtube <- data_frame[data_frame$category_id == "24",]
sum <- youtube[order(youtube$title), ] %>% group_by(title) %>% mutate(change = views - lag(views))
clean_sum <- na.omit(sum)
views <- tapply(clean_sum$change, clean_sum$formatted_trending_date, mean)
final <- data.frame(key = names(views), value = views)
final_data <- mutate(final, month = month.name[month(final$key)], day = day(final$key), year = year(final$key))
```
```{r}
ggplot(data = final_data, aes(x = month, y = day, fill = value)) +
geom_tile(color = "white") +
scale_fill_gradientn(colours = brewer.pal(5, "Blues"), labels = comma) +
scale_x_discrete(limits = c("November", "December", "January", "February", "March", "April", "May", "June")) +
scale_y_continuous(breaks = 1:31, labels = 1:31) +
ggtitle("Views for Trending Entertainment YouTube Videos") +
labs(x = "Month", y = "Day", fill = "Total View Count") +
theme(axis.text = element_text(size = 8), axis.title = element_text(size = 12),
plot.title = element_text(size = 16)) +
theme(plot.title = element_text(hjust = 0.5), legend.title = element_text(hjust = 0.5)) +
theme(panel.background = element_rect(fill = "white"))
```
```{r message = FALSE}
df <- read_csv("USvideos.csv")
data <- mutate(df, formatted_trending_date = ydm(trending_date), publish_date = as.Date(format(df$publish_time, "%Y-%m-%d")))
data_frame <- mutate(data, trending_month = month(formatted_trending_date), trending_day = day(formatted_trending_date), trending_year = year(formatted_trending_date), publish_month = month(publish_time), publish_day = day(publish_time), publish_year = year(publish_time))
youtube <- data_frame[data_frame$category_id == "10",]
sum <- youtube[order(youtube$title), ] %>% group_by(title) %>% mutate(change = views - lag(views))
clean_sum <- na.omit(sum)
views <- tapply(clean_sum$change, clean_sum$formatted_trending_date, mean)
final <- data.frame(key = names(views), value = views)
final_data <- mutate(final, month = month.name[month(final$key)], day = day(final$key), year = year(final$key))
```
```{r}
ggplot(data = final_data, aes(x = month, y = day, fill = value)) +
geom_tile(color = "white") +
scale_fill_gradientn(colours = brewer.pal(5, "Blues"), labels = comma) +
scale_x_discrete(limits = c("November", "December", "January", "February", "March", "April", "May", "June")) +
scale_y_continuous(breaks = 1:31, labels = 1:31) +
ggtitle("Views for Trending Music YouTube Videos") +
labs(x = "Month", y = "Day", fill = "Total View Count") +
theme(axis.text = element_text(size = 8), axis.title = element_text(size = 12),
plot.title = element_text(size = 16)) +
theme(plot.title = element_text(hjust = 0.5), legend.title = element_text(hjust = 0.5)) +
theme(panel.background = element_rect(fill = "white"))
```
```{r message = FALSE}
df <- read_csv("USvideos.csv")
data <- mutate(df, formatted_trending_date = ydm(trending_date), publish_date = as.Date(format(df$publish_time, "%Y-%m-%d")))
data_frame <- mutate(data, trending_month = month(formatted_trending_date), trending_day = day(formatted_trending_date), trending_year = year(formatted_trending_date), publish_month = month(publish_time), publish_day = day(publish_time), publish_year = year(publish_time))
youtube <- data_frame[data_frame$category_id == "26",]
sum <- youtube[order(youtube$title), ] %>% group_by(title) %>% mutate(change = views - lag(views))
clean_sum <- na.omit(sum)
views <- tapply(clean_sum$change, clean_sum$formatted_trending_date, mean)
final <- data.frame(key = names(views), value = views)
final_data <- mutate(final, month = month.name[month(final$key)], day = day(final$key), year = year(final$key))
```
```{r}
ggplot(data = final_data, aes(x = month, y = day, fill = value)) +
geom_tile(color = "white") +
scale_fill_gradientn(colours = brewer.pal(5, "Blues"), labels = comma) +
scale_x_discrete(limits = c("November", "December", "January", "February", "March", "April", "May", "June")) +
scale_y_continuous(breaks = 1:31, labels = 1:31) +
ggtitle("Views for Trending How-To and Style YouTube Videos") +
labs(x = "Month", y = "Day", fill = "Total View Count") +
theme(axis.text = element_text(size = 8), axis.title = element_text(size = 12),
plot.title = element_text(size = 16)) +
theme(plot.title = element_text(hjust = 0.5), legend.title = element_text(hjust = 0.5)) +
theme(panel.background = element_rect(fill = "white"))
```