download_google_trends_data: Download Google Trends data on Covid-19

View source: R/download_google_trends_data.R

download_google_trends_dataR Documentation

Description

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.

Usage

download_google_trends_data(
  search_term = "coronavirus",
  type = "country_day",
  countries = NULL,
  low_search_volume = FALSE,
  pause = TRUE,
  silent = FALSE,
  cached = FALSE
)

Arguments

search_term

Defaults to "coronavirus".

type

The type of data that you want to retrieve. Can be any subset of

  • "country": Relative search activity at the global level, reporting by country.

  • "country_day": Relative search activity at the country level, reporting by country.

  • "region": Relative search activity at the country level, reporting by region.

  • "city": Relative search activity at the country level, reporting by city.

Defaults to 'country_day'.

countries

A character vector of ISO3c country codes that you want to pull detailed data for. By default (countries = NULL) the code pulls detailed data for all countries the the global Google Trend request returns.

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 FALSE.

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 TRUE.

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 TRUE.

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 FALSE.

Details

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.

Value

If only one type was selected, a data frame containing the data. Otherwise, a list containing the desired data frames ordered as in type.

Examples

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)


joachim-gassen/tidycovid19 documentation built on March 21, 2024, 6:57 a.m.