1

I my research, I intend to investigate on Google Trends the search visibility of some animal groups. For this, I am using the gtrendsR package, with the following commands:

> library(gtrendsR)

> keywords = c("Butterfly", "Cockroach", "Parrot", "Ostrich", "Lion", "Platypus", "Alligator") #setting the search terms.

> country = c('BR') #setting the geographic area (Brazil).

> time <- ("2011-01-01 2021-12-31") #setting the period.

> channel <- 'web' #setting the channels.

However, when I try to run the query, an error message appears:

> trends <- gtrends(keywords, gprop = channel, geo = country, time = time)
Error in gtrends(keywords, gprop = channel, geo = country, time = time): length(keyword) <= 5 is not TRUE

Apparently, this way it's not possible to retrieve results for more than 5 keywords (both on the Google Trends site and with gtrendsR package). How could I do this, with this or another R package?

  • Can you just split the `keywords` list into groups of 5 and retrieve the data iteratively with `lapply()/purrr::map()` and then merge after? – Dan Adams Aug 05 '22 at 00:08
  • 1
    A Python solution to this problem which you may be able to adapt [is described here](https://towardsdatascience.com/using-google-trends-at-scale-1c8b902b6bfa). – neilfws Aug 05 '22 at 00:13
  • 1
    @neilfws - that resource makes a great point that the results are **relative** which makes it invalid to combine data from separate queries. – Dan Adams Aug 05 '22 at 00:15
  • @neilfws, the Python solution seems very efficient to me. But would there be an alternative in R? – Arthur Filipe da Silva Aug 05 '22 at 00:24
  • 1
    You can iterate as I suggested but include one control term that will be the most popular in all searches with batches of 4 of your terms of interest. So you just need something that was always searched more than your animals. Perhaps `"COVID"` would work for the time frame you have there. – Dan Adams Aug 05 '22 at 00:30
  • @DanAdams, from what I understand from your explanation, I could gather these result sets to compare them all against each other in a single graph. Thus, would it be possible to visualize a clear output regarding the relative searches among all animals? – Arthur Filipe da Silva Aug 05 '22 at 00:48
  • Yes, that's right. Are you just after the interest over time? – Dan Adams Aug 05 '22 at 00:49
  • Yes, that's what I have in mind. Much obliged! – Arthur Filipe da Silva Aug 05 '22 at 00:54
  • @DanAdams, Oh, a little addition: I also intend to visualize over time by each Brazilian state. Following your suggestion, would it be possible to get the result I want? – Arthur Filipe da Silva Aug 05 '22 at 00:57
  • I think the data over time is only given for the whole specified region (`BR`). The sub-region data seems to be a total over the time window. So you would need to separately specify each state (although I think you can do that in a single query). – Dan Adams Aug 05 '22 at 01:08
  • From the github page I find these state codes for Brasil: `c("BR-AC", "BR-AL", "BR-AP", "BR-AM", "BR-BA", "BR-CE", "BR-ES", "BR-GO", "BR-MA", "BR-MT", "BR-MS", "BR-MG", "BR-PA", "BR-PB", "BR-PR", "BR-PE", "BR-PI", "BR-RJ", "BR-RN", "BR-RS", "BR-RO", "BR-RR", "BR-SC", "BR-SP", "BR-SE", "BR-TO")` – Dan Adams Aug 05 '22 at 01:21

0 Answers0