By running the following chunk, I am retrieving the data of how many searches for psychologist there have been on google over time.
psychologist <- trendy("psychologist")
psychologist %>%
glimpse()
List of 1
$ :List of 7
..$ interest_over_time :'data.frame': 261 obs. of 7 variables:
.. ..$ date : POSIXct[1:261], format: ...
.. ..$ hits : int [1:261] 66 66 66 64 65 66 64 62 65 68 ...
.. ..$ keyword : chr [1:261] "psychologist" "psychologist" "psychologist" "psychologist" ...
.. ..$ geo : chr [1:261] "world" "world" "world" "world" ...
.. ..$ time : chr [1:261] "today+5-y" "today+5-y" "today+5-y" "today+5-y" ...
.. ..$ 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" "Ireland" "New Zealand" ...
.. ..$ hits : chr [1:250] "100" "75" "47" "43" ...
.. ..$ 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] "Miami-Ft. Lauderdale FL" "New York NY" "Philadelphia PA" "West Palm Beach-Ft. Pierce FL" ...
.. ..$ hits : int [1:306] 100 97 96 93 93 90 88 88 86 85 ...
.. ..$ 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': 200 obs. of 5 variables:
.. ..$ location: chr [1:200] "Ghan" "Lismore" "Mornington" "Canberra" ...
.. ..$ hits : int [1:200] NA NA NA 100 100 NA 100 94 94 94 ...
.. ..$ keyword : chr [1:200] "psychologist" "psychologist" "psychologist" "psychologist" ...
.. ..$ geo : chr [1:200] "world" "world" "world" "world" ...
.. ..$ gprop : chr [1:200] "web" "web" "web" "web" ...
..$ related_topics :'data.frame': 34 obs. of 5 variables:
.. ..$ subject : chr [1:34] "100" "16" "11" "9" ...
.. ..$ related_topics: chr [1:34] "top" "top" "top" "top" ...
.. ..$ value : chr [1:34] "Psychologist" "Psychology" "Psychiatrist" "Clinical psychologist" ...
.. ..$ keyword : chr [1:34] "psychologist" "psychologist" "psychologist" "psychologist" ...
.. ..$ category : int [1:34] 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" "99" "73" "73" ...
.. ..$ related_queries: chr [1:50] "top" "top" "top" "top" ...
.. ..$ value : chr [1:50] "psychology" "the psychologist" "psychiatrist" "psychiatrist psychologist" ...
.. ..$ 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
..- attr(*, "class")= chr [1:2] "gtrends" "list"
- attr(*, "class")= chr "trendy"
psychologist %>%
get_interest() %>%
ggplot(aes(x = date, y = hits)) +
geom_line()
This chunk then turned the data I ran from before into a graph of the hits for ‘psychologist’ on google over time.
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))
Continuous limits supplied to discrete scale.
Did you mean `limits = factor(...)` or `scale_*_continuous()`?
This chunk then narrowed the last graph even more by changing the timeline from years to months. This makes the data clearer and easier to understand.
psychologist_US <- trendy("psychologist", geo = "US", from = "2015-01-01", to = "2020-01-01")
This is retrieving the data from google of how many searches for ‘psychologist’ there have been in the US from January 2015 to January 2020
psychologist_US %>%
get_interest_dma() %>%
datatable()
The above chunk then converted the previous data into a datatable to organize it better.
psychologist_countries <- trendy("psychologist", geo = c("US", "CA"), from = "2015-01-01", to = "2020-01-01")
This chunk retrieves data about searches for ‘psychologist’ in both the US and Canada from 2015-2020. The chunk below then turns this data into a line graph comparing the two searches over 12 months.
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.Continuous limits supplied to discrete scale.
Did you mean `limits = factor(...)` or `scale_*_continuous()`?
psychologist_psychiatrist <- trendy(c("psychologist", "psychiatrist"), geo = "US")
This chunk is retrieving the searches for psychologist and psychiatrist in the US. The below chunk is then running this data to become a line graph comparing the amount of searches for each over the years.
psychologist_psychiatrist %>%
get_interest() %>%
ggplot(aes(x = date, y = hits, color = keyword)) +
geom_line()
psychiatrist_images <- trendy("psychiatrist", gprop = "images")
This is retrieving the search for images of psychiatrist from google images
psychologist_images <- trendy("psychologist", gprop = "images")
This is retrieving the search for images of psychologist from google images
psychiatrist_images %>%
psychologist_images
Error in psychologist_images(.) :
could not find function "psychologist_images"
This was one of many attempts to achieve a line graph of the searches for both psychologist and psychiatrist on google images over time. However, I was not able to figure out the right code.