Assignment: Look up “psychologist” with trendyy.
library(tidyverse)
library(DT)
library(trendyy) # Package to access google search data
library(lubridate) # Handles dates and times
- Create a graph of interest in it over time.
psychologist_data<-trendy("psychologist")
Failed to create bus connection: No such file or directory
running command 'timedatectl' had status 1
psychologist_data %>%
get_interest() %>%
ggplot(aes(x=date, y=hits)) +
geom_line()

Here is the trend data for “psychologist” searches over the past five years. Interestingly, it seems to drop sharply at the end of each year and then spike back up fairly consistently.
- Create a graph of monthly interest in it.
psychologist_data %>%
get_interest() %>%
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))+
labs(title="'Psychologist' Google searches over five years")

Here is the graph for monthly data of “psychologist” searches. It seems to decline steadily from the beginning of the year until July, and then quickly climbs up to its peak in September before falling again at the end of the year.
- Create a datatable of interest by DMA.
psychologist_us <- trendy("psychologist", geo = "US")
psychologist_us %>%
get_interest_dma() %>%
datatable()
Here is a datatable showing “psychologist” searches by DMA. The Portland-Auburn, Maine area shows the highest, with most of top 50 areas being on the eastern half of the US. The area with the least amount of searches is Spokane, Washington.
- Compare US vs. Canadian (CA) interest in psychologist by month, and create a line graph.
psychologist_countries <- trendy("psychologist", geo = c("US", "CA"), from = "2015-01-01", to = "2020-01-01")
psychologist_countries %>%
get_interest() %>%
ggplot(aes(x=date, y=hits, color=geo))+
geom_line()+
labs(title = "US vs. Canadian internet interest in 'psychologist' by month")

- Compare interest in psychologist to psychiatrist over time, and create a line graph.
psychologist_psychiatrist <- trendy(c("psychologist", "psychiatrist"))
psychologist_psychiatrist %>%
get_interest() %>%
ggplot(aes(x=date, y= hits, color= keyword))+
geom_line()+
labs(title= "'Psychologist' vs. 'Psychiatrist' Google searches over five years")

Here’s a graph comparing the Google searches of “psychologist” (the blue line) to “psychiatrist” (the orange line). Interestingly, they both have a similar pattern in terms of search spikes throughout the year, but “psychologist” searches occur at a higher frequency than “psychiatrist.”
- Compare interest in psychologist to psychiatrist in google images over time, and create a line graph.
psychologist_psychiatrist_images <- trendy(c("psychologist", "psychiatrist"), gprop = "images")
psychologist_psychiatrist_images %>%
get_interest() %>%
ggplot(aes(x=date, y= hits, color = keyword))+
geom_line()+
labs(title= "'Psychologist' vs. 'Psychiatrist' Google image searches over five years")

Here is the data for Google image searches of “psychologist” (blue line) and “psychiatrist” (orange line). In comparison to the previous graph, this one is far more mixed between the two searches. There are significant spikes for “psychologist” image searches about halfway through 2017, the end of 2018 and beginning of 2019, and there are 11 different negative spikes for “psychiatrist” throughout these five years. Beyond that, it’s a fairly even split bewteen the two searches.
- Annotate the document and publish it to rpubs.com.
LS0tCnRpdGxlOiAiUiBOb3RlYm9vayIKb3V0cHV0OiBodG1sX25vdGVib29rCi0tLQpBc3NpZ25tZW50OiBMb29rIHVwICJwc3ljaG9sb2dpc3QiIHdpdGggdHJlbmR5eS4KCgpgYGB7cn0KbGlicmFyeSh0aWR5dmVyc2UpCmxpYnJhcnkoRFQpCmxpYnJhcnkodHJlbmR5eSkgICAgICAgICAgICAgICAgIyBQYWNrYWdlIHRvIGFjY2VzcyBnb29nbGUgc2VhcmNoIGRhdGEKbGlicmFyeShsdWJyaWRhdGUpICAgICAgICAgICAgICAgIyBIYW5kbGVzIGRhdGVzIGFuZCB0aW1lcwpgYGAKCjEuIENyZWF0ZSBhIGdyYXBoIG9mIGludGVyZXN0IGluIGl0IG92ZXIgdGltZS4KYGBge3J9CnBzeWNob2xvZ2lzdF9kYXRhPC10cmVuZHkoInBzeWNob2xvZ2lzdCIpIAogIApwc3ljaG9sb2dpc3RfZGF0YSAlPiUgCiAgZ2V0X2ludGVyZXN0KCkgJT4lIAogIGdncGxvdChhZXMoeD1kYXRlLCB5PWhpdHMpKSArCiAgZ2VvbV9saW5lKCkKYGBgCkhlcmUgaXMgdGhlIHRyZW5kIGRhdGEgZm9yICJwc3ljaG9sb2dpc3QiIHNlYXJjaGVzIG92ZXIgdGhlIHBhc3Qg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