sfda
Load the necessary 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) # Package to access google search data
library(lubridate) # Handles dates and times
##
## Attaching package: 'lubridate'
## The following object is masked from 'package:base':
##
## date
Utilize Google for information on ‘psychologist’ searches
psychologist <- gtrends("psychologist")
## Warning in system("timedatectl", intern = TRUE): running command
## 'timedatectl' had status 1
glimpse(psychologist)
## List of 7
## $ interest_over_time :'data.frame': 261 obs. of 6 variables:
## ..$ date : POSIXct[1:261], format: "2014-02-16" ...
## ..$ hits : int [1:261] 74 76 75 69 71 71 74 72 66 69 ...
## ..$ keyword : chr [1:261] "psychologist" "psychologist" "psychologist" "psychologist" ...
## ..$ geo : chr [1:261] "world" "world" "world" "world" ...
## ..$ gprop : chr [1:261] "web" "web" "web" "web" ...
## ..$ category: int [1:261] 0 0 0 0 0 0 0 0 0 0 ...
## $ interest_by_country:'data.frame': 250 obs. of 5 variables:
## ..$ location: chr [1:250] "Australia" "South Africa" "Swaziland" "Ireland" ...
## ..$ hits : chr [1:250] "100" "79" "" "51" ...
## ..$ keyword : chr [1:250] "psychologist" "psychologist" "psychologist" "psychologist" ...
## ..$ geo : chr [1:250] "world" "world" "world" "world" ...
## ..$ gprop : chr [1:250] "web" "web" "web" "web" ...
## $ interest_by_region : NULL
## $ interest_by_dma :'data.frame': 306 obs. of 5 variables:
## ..$ location: chr [1:306] "Fresno-Visalia CA" "Laredo TX" "Bluefield-Beckley-Oak Hill WV" "St. Joseph MO" ...
## ..$ hits : int [1:306] 100 96 96 94 93 93 92 91 91 89 ...
## ..$ keyword : chr [1:306] "psychologist" "psychologist" "psychologist" "psychologist" ...
## ..$ geo : chr [1:306] "world" "world" "world" "world" ...
## ..$ gprop : chr [1:306] "web" "web" "web" "web" ...
## $ interest_by_city :'data.frame': 65 obs. of 5 variables:
## ..$ location: chr [1:65] "Canberra" "Melbourne" "Gold Coast" "Adelaide" ...
## ..$ hits : int [1:65] NA 100 NA 91 87 84 83 79 70 NA ...
## ..$ keyword : chr [1:65] "psychologist" "psychologist" "psychologist" "psychologist" ...
## ..$ geo : chr [1:65] "world" "world" "world" "world" ...
## ..$ gprop : chr [1:65] "web" "web" "web" "web" ...
## $ related_topics :'data.frame': 28 obs. of 5 variables:
## ..$ subject : chr [1:28] "100" "23" "9" "8" ...
## ..$ related_topics: chr [1:28] "top" "top" "top" "top" ...
## ..$ value : chr [1:28] "Psychologist" "Psychology" "Psychiatrist" "Salary" ...
## ..$ keyword : chr [1:28] "psychologist" "psychologist" "psychologist" "psychologist" ...
## ..$ category : int [1:28] 0 0 0 0 0 0 0 0 0 0 ...
## ..- attr(*, "reshapeLong")=List of 4
## .. ..$ varying:List of 1
## .. .. ..- attr(*, "v.names")= chr "value"
## .. .. ..- attr(*, "times")= chr "top"
## .. ..$ v.names: chr "value"
## .. ..$ idvar : chr "id"
## .. ..$ timevar: chr "related_topics"
## $ related_queries :'data.frame': 50 obs. of 5 variables:
## ..$ subject : chr [1:50] "100" "85" "69" "68" ...
## ..$ related_queries: chr [1:50] "top" "top" "top" "top" ...
## ..$ value : chr [1:50] "psychology" "the psychologist" "psychologist psychiatrist" "psychiatrist" ...
## ..$ keyword : chr [1:50] "psychologist" "psychologist" "psychologist" "psychologist" ...
## ..$ category : int [1:50] 0 0 0 0 0 0 0 0 0 0 ...
## ..- attr(*, "reshapeLong")=List of 4
## .. ..$ varying:List of 1
## .. .. ..- attr(*, "v.names")= chr "value"
## .. .. ..- attr(*, "times")= chr "top"
## .. ..$ v.names: chr "value"
## .. ..$ idvar : chr "id"
## .. ..$ timevar: chr "related_queries"
## - attr(*, "class")= chr [1:2] "gtrends" "list"
Create a table to depict the amount of google searches for ‘psychologist’ over time. As one can see, there is slight seasonal pattern to people searching for this term.
psychologist$interest_over_time%>%
ggplot(aes(x = date, y = hits)) +
geom_line() +
theme_minimal() +
labs(title = "Google Searches for 'psychologist' over time")
Here is a graph illustrating the amount of ‘hits’ for the term ‘psychologist every month. ’Hits’ are basically searches that people have done on a particular word or group of words.
psychologist$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 Searchs for 'psychologist,' by month")
Next create a table showing searches for ‘psychologist’ in relation to DMA (Designated Market Area). This represents a specific televised market of people.
psychologist$interest_by_dma %>%
datatable()
Retireve data comparing the United States to Canada searches for ‘pschologist.’
psychologist_US_CA <- gtrends("psychologist", geo =c("US", "CA"))
Next step is to graph this comparison using line graphs. It appears that the U.S. searches for this term a bit more often than Canada!
psychologist_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 'pscyhologist,' by month")
Get data on pscyhologist vs. psychiatrist searches:
psychologist_pscyhiatrist <- gtrends(c("psychologist", "psychiatrist"))
Create a comparison line graph between searches for ‘psychologist’ and ‘psychiatrist’ over a period of time. As one can see, ‘psychologist’ is searched more often than ‘psychiatrist.’
psychologist_pscyhiatrist$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")
psychologist_psychiatrist <- gtrends(c("psychologist", "psychiatrist"), gprop = "images")
Finally create a line grapth illustrating the differences between ‘pschologist’ and ‘psychiatrist in relation to Google Image Searches. And to reitereate, it appears that ’psychologist’ is searched more than ‘psychiatrist.’
psychologist_pscyhiatrist$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")