Load packages
library(tidyverse)
## ── Attaching packages ─────────────────────────────────── tidyverse 1.2.1 ──
## ✔ ggplot2 3.1.0 ✔ purrr 0.2.5
## ✔ tibble 2.0.0 ✔ dplyr 0.7.8
## ✔ tidyr 0.8.2 ✔ stringr 1.3.1
## ✔ readr 1.3.1 ✔ forcats 0.3.0
## ── Conflicts ────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag() masks stats::lag()
library(DT)
library(gtrendsR) # Package to access google search data
library(lubridate) # Handles dates and times
##
## Attaching package: 'lubridate'
## The following object is masked from 'package:base':
##
## date
Get searches of “psychologist”
psych <- gtrends("psychologist")
## Warning in system("timedatectl", intern = TRUE): running command
## 'timedatectl' had status 1
psych$interest_over_time %>%
ggplot(aes(x = date, y =hits)) +
geom_line() +
theme_minimal() +
labs(title = "Google searches for 'psychologist' over time")
psych$interest_over_time %>%
mutate(month = month(date)) %>%
group_by(month) %>%
summarize(hits_per_month = mean(hits)) %>%
ggplot(aes(x = month, y = hits_per_month)) +
geom_line() +
scale_x_discrete(limits = c(1:12)) +
theme_minimal() +
labs(title = "Google searches for 'psychologist' by month")
psych$interest_by_dma %>%
datatable()
Get data comparing United States to Canadian searches for psychologist:
psych_US_CA <- gtrends("psychologist" , geo = c("US" , "CA"))
psych_US_CA$interest_over_time %>%
mutate(month = month(date)) %>%
group_by(month, geo) %>%
summarize(hits_per_month = mean(hits)) %>%
ggplot(aes(x = month, y = hits_per_month, color = geo)) +
geom_line() +
scale_x_discrete(limits = c(1:12)) +
theme_minimal() +
labs(title = "Comparing United States and Canadian searches for 'psychologist' by month")
Get data on psychologist vs. psychistrist searches:
psycho_psychi <- gtrends(c("psychologist" , "psychiatrist"))
psycho_psychi$interest_over_time %>%
ggplot(aes(x = date, y = hits, color = keyword)) +
geom_line() +
theme_minimal() +
labs(title = "Google searches for 'psychologist vs. psychiatrist over time'")
psycho_psychi_images <- gtrends(c("psychologist" , "psychiatrist"), gprop ="images")
psycho_psychi_images$interest_over_time %>%
ggplot(aes(x = date, y = hits, color = keyword)) +
geom_line() +
theme_minimal() +
labs(title = "Google image searches for 'psychologist vs. psychiatrist over time'")