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
)

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.

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.

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.

Examples

df <- download_google_trends_data(type = "country", silent = TRUE, cached = TRUE) df %>% dplyr::select(iso3c, gtrends_score) %>% dplyr::arrange(-gtrends_score)
#> iso3c gtrends_score #> 1 ITA 100 #> 2 ESP 82 #> 3 QAT 76 #> 4 GBR 74 #> 5 IRL 68 #> 6 FRA 62 #> 7 CHE 55 #> 8 URY 54 #> 9 ARE 52 #> 10 AUS 50 #> 11 ARG 49 #> 12 NPL 45 #> 13 USA 45 #> 14 PER 44 #> 15 ROU 43 #> 16 ZAF 42 #> 17 NZL 41 #> 18 AUT 40 #> 19 CAN 40 #> 20 PAN 39 #> 21 KWT 39 #> 22 COL 38 #> 23 SGP 36 #> 24 DEU 36 #> 25 BEL 36 #> 26 CHL 35 #> 27 PRY 33 #> 28 CRI 33 #> 29 IND 32 #> 30 BOL 32 #> 31 GHA 31 #> 32 ECU 30 #> 33 MEX 29 #> 34 GTM 29 #> 35 VEN 27 #> 36 PRT 26 #> 37 PAK 25 #> 38 MAR 24 #> 39 BGD 24 #> 40 DOM 24 #> 41 BRA 24 #> 42 KEN 23 #> 43 LKA 23 #> 44 DZA 20 #> 45 NLD 18 #> 46 MYS 15 #> 47 DNK 15 #> 48 SAU 14 #> 49 NGA 14 #> 50 SWE 14 #> 51 HKG 11 #> 52 ISR 11 #> 53 NOR 11 #> 54 PHL 10 #> 55 GRC 8 #> 56 EGY 6 #> 57 POL 4 #> 58 THA 3 #> 59 TUR 3 #> 60 IDN 2 #> 61 VNM 2 #> 62 RUS 2 #> 63 JPN 1
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)
#> region gtrends_score #> 1 Thuringia 100 #> 2 Saarland 94 #> 3 Rhineland-Palatinate 92 #> 4 Baden-Württemberg 91 #> 5 Saxony-Anhalt 88 #> 6 Bavaria 88 #> 7 Brandenburg 87 #> 8 Bremen 87 #> 9 North Rhine-Westphalia 87 #> 10 Lower Saxony 87 #> 11 Berlin 86 #> 12 Mecklenburg-Vorpommern 85 #> 13 Schleswig-Holstein 83 #> 14 Saxony 79 #> 15 Hamburg 77 #> 16 Hesse 74
lst[[2]] %>% dplyr::filter(iso3c == "DEU") %>% dplyr::select(city, gtrends_score) %>% dplyr::arrange(-gtrends_score)
#> city gtrends_score #> 1 Nordstemmen 100 #> 2 Schlitz 83 #> 3 Gütersloh 83 #> 4 Sulzbach 81 #> 5 Angermünde 80 #> 6 Stuttgart 76 #> 7 Erftstadt 76 #> 8 Neuss 75 #> 9 Hildesheim 68