/
xkcd_words_impact.R
84 lines (69 loc) · 1.9 KB
/
xkcd_words_impact.R
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
options(bitmapType='cairo')
options(scipen = 999)
# library(bbbi)
# library(data.table)
library(dplyr)
library(tidyr)
library(ggplot2)
# Define your workspace: "X:/xxx/"
wd <- "D:/github/xkcd_survey/"
setwd(wd)
terms <- c(
"Unitory",
"Rife",
"Soliloquy",
"Regolith",
"Tribution",
"Stipple",
"Fination",
"Modicum",
"Trephony",
"Amiable",
"Fleek",
"Apricity",
"Lithe",
"Revergent",
"Cadine",
"Phoropter",
"Slickle",
"Hubris",
"Peristeronic",
"Salient")
f.gtrend.csv.read <- function(x){
read.csv(file=paste0("data/report_", sprintf("%02d", as.numeric(x)), ".csv"),
na.strings = " ",
stringsAsFactors = FALSE,
# 173 is last timeseries row, minus skip, minus header = 168
skip = 4, nrows = 168)
}
# merge all four google .csvs
data.raw <- f.gtrend.csv.read(1) %>%
merge(f.gtrend.csv.read(2)) %>%
merge(f.gtrend.csv.read(3)) %>%
merge(f.gtrend.csv.read(4)) %>%
mutate(
Time = as.POSIXct(strptime(Time, "%Y-%m-%d-%H:%M UTC", tz="UTC"))
)
# big pile of trend lines, starting September-01
data.raw %>%
gather(term, trend, -Time) %>%
ggplot()+
geom_line(size=1)+
aes(x=Time, y=trend, colour=term)+
coord_cartesian(xlim = c(as.POSIXct(strptime("2015-09-01", "%Y-%m-%d", tz="UTC")),
max(data.raw$Time)))+
ggtitle("Google Search Trends of the xkcd survey English Terms")
ggsave(file="xkcd-messy-trends.png")
# faceted for better overview
data.raw %>%
gather(term, trend, -Time) %>%
ggplot()+
geom_line(size=1)+
aes(x=Time, y=trend, colour=term)+
coord_cartesian(xlim = c(as.POSIXct(strptime("2015-09-01", "%Y-%m-%d", tz="UTC")),
max(data.raw$Time)))+
facet_wrap(~term)+
guides(colour=FALSE)+
theme(axis.text.x=element_text(angle = 45, hjust = 1))+
ggtitle("Google Search Trends of the xkcd survey English Terms")
ggsave(file="xkcd-facet-trends.png")