-
Notifications
You must be signed in to change notification settings - Fork 68
/
gtrends-script.R
32 lines (22 loc) · 1.03 KB
/
gtrends-script.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
library(gtrendsR)
library(ggplot2)
library(tidyverse)
bitcoin.trend <- gtrends(c("bitcoin"), gprop = "web", time = "all")[[1]]
class(bitcoin.trend)
head(bitcoin.trend)
class(bitcoin.trend$date)
ggplot(data = bitcoin.trend) + geom_line(mapping = aes(x= date, y = hits))
?gtrends
bitcoin.trend <- bitcoin.trend %>% filter(date >= as.Date("2009-01-01"))
ggplot(data = bitcoin.trend) +
geom_line(mapping = aes(x= date, y = hits)) +
geom_vline(xintercept = as.Date("2017-01-20"), color = "red") #trump inauguration
library(Quandl)
bitcoin.price <- Quandl("BCHARTS/BITSTAMPUSD")
bitcoin.price <- bitcoin.price %>% filter(Date %in% bitcoin.trend$date) %>% select(Date, Close) %>% rename(date = Date, price = Close) %>% mutate(price = price*100/max(price))
bitcoin <- left_join(x = bitcoin.trend, y= bitcoin.price, by = "date")
head(bitcoin)
ggplot(data = bitcoin) +
geom_line(mapping = aes(x= date, y = hits)) +
geom_line(mapping = aes(x= date, y = price), color = "gray") +
geom_vline(xintercept = as.Date("2017-01-20"), color = "red")