View source: R/download_google_trends_data.R
download_google_trends_data | R Documentation |
Downloads Google Trends data (https://trends.google.com/trends/) about the 2020 search activity for a given search term at global and country levels. The search term defaults to "coronavirus" to reflect the relative public attention to the Covid-19 pandemic.
download_google_trends_data(
search_term = "coronavirus",
type = "country_day",
countries = NULL,
low_search_volume = FALSE,
pause = TRUE,
silent = FALSE,
cached = FALSE
)
search_term |
Defaults to "coronavirus". |
type |
The type of data that you want to retrieve. Can be any subset of
Defaults to 'country_day'. |
countries |
A character vector of ISO3c country codes that you want
to pull detailed data for. By default ( |
low_search_volume |
Whether you want the include countries with low
search volume. This increases the list of countries that are pulled
considerably and also the risk that you hit a Google Trend search limit.
Use with care. Defaults to |
pause |
Whether you want the code to pause for a 2 to 5 seconds period
between Google Trend API calls. As Google Trends has an unknown rate
limit, this is probably a good idea and thus defaults to |
silent |
Whether you want the function to send some status messages to
the console. Might be informative as downloading will take some time
and thus defaults to |
cached |
Whether you want to download the cached version of the data
from the tidycovid19 Github repository instead of retrieving the
data from the authorative source. Downloading the cached version is
faster and the cache is updated daily. Defaults to |
Uses the gtrendsR
package. Please note that Google Trends
only reports relative search volume. For each data frame, the values
are standardized so that the observations with the highest search volume
gets a score of 100 and the other scores of the data frame are relative
to that. This implies that comparisons across data frames are not
feasible. When Google Trends reports a score of "<1" this is
translated to 0.5 in the data.
If only one type
was selected, a data frame containing the
data. Otherwise, a list containing the desired data frames ordered as
in type
.
df <- download_google_trends_data(type = "country", silent = TRUE, cached = TRUE)
df %>%
dplyr::select(iso3c, gtrends_score) %>%
dplyr::arrange(-gtrends_score)
lst <- download_google_trends_data(type = c("region", "city"), silent = TRUE, cached = TRUE)
lst[[1]] %>%
dplyr::filter(iso3c == "DEU") %>%
dplyr::select(region, gtrends_score) %>%
dplyr::arrange(-gtrends_score)
lst[[2]] %>%
dplyr::filter(iso3c == "DEU") %>%
dplyr::select(city, gtrends_score) %>%
dplyr::arrange(-gtrends_score)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.