Assignment: Look up “psychologist” with trendyy.
psychologist <- trendy("psychologist")
flu %>%
glimpse()
List of 1
$ :List of 7
..$ interest_over_time :'data.frame': 260 obs. of 7 variables:
.. ..$ date : POSIXct[1:260], format: "2017-02-19" "2017-02-26" "2017-03-05" "2017-03-12" ...
.. ..$ hits : int [1:260] 13 12 12 9 9 9 9 8 7 7 ...
.. ..$ keyword : chr [1:260] "flu" "flu" "flu" "flu" ...
.. ..$ geo : chr [1:260] "world" "world" "world" "world" ...
.. ..$ time : chr [1:260] "today+5-y" "today+5-y" "today+5-y" "today+5-y" ...
.. ..$ gprop : chr [1:260] "web" "web" "web" "web" ...
.. ..$ category: int [1:260] 0 0 0 0 0 0 0 0 0 0 ...
..$ interest_by_country:'data.frame': 250 obs. of 5 variables:
.. ..$ location: chr [1:250] "Falkland Islands (Islas Malvinas)" "United States" "Cook Islands" "Northern Mariana Islands" ...
.. ..$ hits : int [1:250] NA 100 NA NA NA 85 NA NA 82 81 ...
.. ..$ keyword : chr [1:250] "flu" "flu" "flu" "flu" ...
.. ..$ 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] "Tri-Cities TN-VA" "Jonesboro AR" "Bluefield-Beckley-Oak Hill WV" "Ft. Smith-Fayetteville-Springdale-Rogers AR" ...
.. ..$ hits : chr [1:306] "100" "97" "96" "95" ...
.. ..$ keyword : chr [1:306] "flu" "flu" "flu" "flu" ...
.. ..$ geo : chr [1:306] "world" "world" "world" "world" ...
.. ..$ gprop : chr [1:306] "web" "web" "web" "web" ...
..$ interest_by_city :'data.frame': 58 obs. of 5 variables:
.. ..$ location: chr [1:58] "Chapmansboro" "Plano" "Louisville" "Raleigh" ...
.. ..$ hits : int [1:58] NA NA NA NA NA NA NA NA NA NA ...
.. ..$ keyword : chr [1:58] "flu" "flu" "flu" "flu" ...
.. ..$ geo : chr [1:58] "world" "world" "world" "world" ...
.. ..$ gprop : chr [1:58] "web" "web" "web" "web" ...
..$ related_topics :'data.frame': 40 obs. of 5 variables:
.. ..$ subject : chr [1:40] "100" "22" "15" "14" ...
.. ..$ related_topics: chr [1:40] "top" "top" "top" "top" ...
.. ..$ value : chr [1:40] "Influenza" "Influenza vaccine" "Common cold" "Death" ...
.. ..$ keyword : chr [1:40] "flu" "flu" "flu" "flu" ...
.. ..$ category : int [1:40] 0 0 0 0 0 0 0 0 0 0 ...
.. ..- attr(*, "reshapeLong")=List of 4
..$ related_queries :'data.frame': 50 obs. of 5 variables:
.. ..$ subject : chr [1:50] "100" "53" "52" "31" ...
.. ..$ related_queries: chr [1:50] "top" "top" "top" "top" ...
.. ..$ value : chr [1:50] "the flu" "flu shot" "flu symptoms" "spanish flu" ...
.. ..$ keyword : chr [1:50] "flu" "flu" "flu" "flu" ...
.. ..$ category : int [1:50] 0 0 0 0 0 0 0 0 0 0 ...
.. ..- attr(*, "reshapeLong")=List of 4
..- attr(*, "class")= chr [1:2] "gtrends" "list"
- attr(*, "class")= chr "trendy"
psychologist %>%
get_interest() %>%
ggplot(aes(x = date, y = hits)) +
geom_line()
About 2/3 of the way through 2020 interest in psychologist was at an all time high, on the contrary, interest in psychologist was at its lowest in right about 2018.
psychologist %>%
get_interest() %>%
mutate(month = month(date)) %>% # Create a new variable called month
group_by(month) %>% # Combine months across weeks and years
summarize(hits_per_month = mean(hits)) %>% # Average number of searches for each month
ggplot(aes(x = month, y = hits_per_month)) + # graph it
geom_line() +
scale_x_discrete(limits = c(1:12))
Warning: Continuous limits supplied to discrete scale.
Did you mean `limits = factor(...)` or `scale_*_continuous()`?
According to this graph, interest in psychologist peaks around September (or month 9).
psychologist_US <- trendy("psychologist", geo = "US", from = "2015-01-01", to = "2020-01-01")
psychologist_US %>%
get_interest_dma() %>%
datatable()
NA
The number 1 spot goes to Bakersfield CA.
psychologist_countries <- trendy("psychologist", geo = c("US", "CA"), from = "2015-01-01", to = "2020-01-01")
psychologist_countries %>%
get_interest() %>%
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 = "Internet searches for 'psychologist' over time, by country")
`summarise()` has grouped output by 'month'. You can override using the `.groups` argument.
Warning: Continuous limits supplied to discrete scale.
Did you mean `limits = factor(...)` or `scale_*_continuous()`?
Interest in psychologist is similarly frequent in Canada and the United States.
psychologist_psychiatrist <- trendy(c("psychologist", "psychiatrist"), geo = "US")
psychologist_psychiatrist %>%
get_interest() %>%
ggplot(aes(x = date, y = hits, color = keyword)) +
geom_line()
From the data diplayed in the graph, it appears that psychologist is more frequently looked up than psychiatrist.
psychologist_images <- trendy(c("psychologist","psychiatrist"), gprop = "images")
psychologist_images %>%
get_interest() %>%
ggplot(aes(x = date, y = hits, color = keyword)) +
geom_line() +
theme_minimal() +
labs(title = "Google image searches for 'psychologist or psychiatrist'")
It is obvious in the graph that psychologist is more frequently looked at through images.