The gtrendsR package

The gtrendsR package provides a way to access Google Trends from R. It is useful to make searches reproducible, but do not make many calls in a short period of time because Google will block you. Always save the data as soon as you got it.

Installing the package is as simple as any other package:

install.packages("gtrendsR")

And loading it as well:

library(gtrendsR)
## Warning: replacing previous import 'vctrs::data_frame' by 'tibble::data_frame'
## when loading 'dplyr'

Its main fuction is call gtrends, which allows you to query Google Trends automatically. Take a look to the documentation of the function with this command:

?gtrends

Among its parameters, four are important for us:

For example, we can search for the terms “2013” and “2015” from all over the world including low search volume regions and on the year 2014:

result <- gtrends(keyword = c("2013","2015"), geo = "", time="2014-01-01 2014-12-31", low_search_volume = T)

The result is an object with various data frames. For example, interest_over_time contains the time series with the volume on its column “hits”:

head(result$interest_over_time)
##         date hits keyword   geo                  time gprop category
## 1 2014-01-05   54    2013 world 2014-01-01 2014-12-31   web        0
## 2 2014-01-12   49    2013 world 2014-01-01 2014-12-31   web        0
## 3 2014-01-19   41    2013 world 2014-01-01 2014-12-31   web        0
## 4 2014-01-26   40    2013 world 2014-01-01 2014-12-31   web        0
## 5 2014-02-02   37    2013 world 2014-01-01 2014-12-31   web        0
## 6 2014-02-09   32    2013 world 2014-01-01 2014-12-31   web        0

And interest_by_country contains the volume across countries:

head(result$interest_by_country)
##   location hits keyword   geo gprop
## 1  Algeria  100    2013 world   web
## 2  Moldova   90    2013 world   web
## 3  Armenia   90    2013 world   web
## 4 Pakistan   86    2013 world   web
## 5     Cuba   73    2013 world   web
## 6  Comoros   69    2013 world   web