-
Notifications
You must be signed in to change notification settings - Fork 0
/
TrendsElection.Rmd
63 lines (51 loc) · 1.25 KB
/
TrendsElection.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
---
title: "Trend"
author: "Joost Klooster"
date: "27-9-2020"
output: pdf_document
---
```{r}
install.packages("tidyverse")
install.packages("lubridate")
install.packages("dygraphs")
install.packages("gtrendsR")
install.packages("dplyr")
install.packages("maps")
install.packages("prophet")
```
```{r}
library(tidyverse)
library(lubridate)
library(dygraphs)
library(gtrendsR)
library(dplyr)
library(maps)
library(prophet)
```
```{r}
election <- gtrends(keyword=c("Trump", "Biden"), geo="US", time = "today 12-m")
```
```{r}
names(election) #shows different data frames
```
```{r}
election$interest_by_region %>%
filter(keyword == "Biden") %>%
arrange(desc(hits)) #filters on highest to lowest
```
```{r}
mappedelection <- election$interest_by_region %>%
mutate(region = tolower(location)) %>%
filter(region %in% region,
keyword == 'Trump') %>%
select(region, hits) %>%
arrange(desc(hits))
mappedelection
```
```{r}
states_map <- map_data("state")
votes_map <- left_join(states_map, mappedelection, by = "region")
ggplot(votes_map, aes(long, lat, group = group))+
geom_polygon(aes(fill = hits), color = "white")+
scale_fill_viridis_c(alpha = 1, direction = -1, option = "E")
```