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)
library(lubridate)
## 
## Attaching package: 'lubridate'
## The following object is masked from 'package:base':
## 
##     date

Get searches of “psychologists”:

psych <- gtrends("psychologists")
## Warning in system("timedatectl", intern = TRUE): running command
## 'timedatectl' had status 1
  1. Graph of interest for ‘psychologists’ over time:
psych$interest_over_time %>% 
  ggplot(aes(x = date, y = hits)) +
  geom_line() +
  theme_minimal() +
  labs(title = "Google searches for 'psychologists' over time")

  1. Graph of monthly interest in ‘psychologists’:
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")

  1. Data table of interest by DMA:
psych$interest_by_dma %>% 
  datatable()
  1. Get data for comparing US to Canadian searches for psychologists:
psych_US_CA <- gtrends("psychologists", geo= c("US", "CA"))

Graph it over time:

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 US and Canadian searchs for 'psychologist,' by month")

  1. Get data on psychologists vs. psychiatrist searches:
psycho_psychi <- gtrends(c("psychologist", "psychiatrist"))

Graph it over time:

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")

  1. Get data to compare interest in psychologist to psychiatrist in google images over time
psycho_psychi_images <- gtrends(c("psychologist", "psychiatrist"), gprop = "images")

Graph it over time:

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")