Load Packages:

library(tidyverse)
## ── Attaching packages ──────────────────────────────────────────────────── tidyverse 1.2.1 ──
## ✔ ggplot2 3.1.0     ✔ purrr   0.3.0
## ✔ tibble  2.0.1     ✔ 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 “psychlogist”

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

  1. Monthly interest in it
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. A datatable of interest by DMA
psych$interest_by_dma %>%
  datatable()
  1. US vs. Canadian (CA) interest in psychologist by month

Get data comparing US to Canadian searches for psychologist:

psych_US_CA <- gtrends("psychologist", geo = c("US", "CA"))

Graph it:

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 searches for 'psychologist', by month")

  1. Interest in psychologist to psychiatrist over time

Get data on psychologist vs. psychiatrist searches:

psycho_psychi <- gtrends(c("psychologist", "psychiatrist"))

Graph it:

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. Interest in psychologist to psychiatrist in google images over time

Get data:

psycho_psychi_images <- gtrends(c("psychologist", "psychiatrist"), gprop = "images")

Graph it:

psycho_psychi_images$interest_over_time %>%
  ggplot(aes(x = date, y = hits, color = keyword)) +
  geom_line() +
  theme_minimal() +
  labs(title = "Google images searches for 'psychologist' vs. 'psychiatrist' over time")