Perform and Display Google Trends Queries

An interface for retrieving and displaying the information returned online by Google Trends is provided. Trends (number of hits) over the time as well as geographic representation of the results can be displayed.


gtrendsR provides an interface for retrieving and displaying Google Trends information.

Trends (number of hits) over time as well as geographic representation of the results can be displayed.

In this simple example, trends for keywords nhl, nba and nfl are retrieved and then plotted from R.

library(gtrendsR)
usr <- "user@gmail.com"  # alternatively store as options() or env.var
psw <- "password"        # idem
gconnect(usr, psw)       # stores handle in environment
sport_trend <- gtrends(c("nhl", "nba", "nfl"))
plot(sport_trend)        # data set also included in package

It is also possible to plot geographical data using googleVis as follow.

plot(sport_trend, type = "geo", which = 5)
plot(sport_trend, type = "geo", which = 6)
plot(sport_trend, type = "geo", which = 7)

Should you have trouble connecting, and also use two-factor authentication on your Google Account, then consider creating another Google account (without two-factor authentication) which should allow automated (i.e. programmatic) connection here.

Since release 1.3.0, the package is on CRAN and can be installed via

install.packages("gtrendsR")

Pre-release versions can be install directly from this repository via

if (!require("devtools")) install.packages("devtools")
devtools::install_github("PMassicotte/gtrendsR")

Philippe Massicotte and Dirk Eddelbuettel

GPL (>= 2)

News

gtrendsR 1.3.4 (Unreleased)

  • Fixing loging issue due to backdoor changes made by Google (#103). Thanks to @MrLoh for initial implementation and suggestions.

  • Fixing crash occuring when monthly data was returned (#81).

  • gtrends() will throw a warning if data is returned monthly (#80).

  • gtrends() is now correctly detecting when quota limit is reached (#90).

gtrendsR 1.3.3

  • A ggplot2 object can now be returned for further customization. plot(gtrends("NHL")) + ggtitle("NHL trend") + theme(legend.position="none")

  • Support for hourly and daily data (#67). For example, it is now possible to have hourly data for the last seven days with gtrends("nhl", geo = "CA", res = "7d"). Use ?gtrends for more information about the time resolution supported by the package.

  • Support for categorties (#46). Ex.: gtrends("NHL", geo = "US", cat = "0-20") will search only in the sport category.

  • Some countries (ex: Hong Kong) were missing from the list (#69).

  • Various typos and documentation work.

gtrendsR 1.3.2

  • Added support for sub-countries (#25). Ex.: gtrends("NHL", geo = "CA-QC") will return trends data for Québec province in Canada. The list of supported sub-countries can be obtained via data(countries).

  • Data parsing should work for any data returned by Google Trends (i.e. countries independent).

  • Better support for queries using keywords in different languages (#50, #57). Ex.: gtrends("蘋果", geo = "TW")

  • Now able to specify up to five countries (#53) via gtrends("NHL", geo = c("CA", "US"))

  • Fixing issue #51 allowing UK-based queries via geo = "GB"

gtrendsR 1.3.1

  • Fixing issue #34 where connection verification was not done properly.
  • Now able to use more latin character in query. For example: gtrends("montréal").
  • Can now deal with data returned other than in English language.

gtrendsR 1.3.0

  • First version of gtrendsR

Reference manual

It appears you don't have a PDF plugin for this browser. You can click here to download the reference manual.

install.packages("gtrendsR")

1.3.5 by Philippe Massicotte, a year ago


https://github.com/PMassicotte/gtrendsR


Report a bug at https://github.com/PMassicotte/gtrendsR/issues


Browse source code at https://github.com/cran/gtrendsR


Authors: Philippe Massicotte [aut, cre], Dirk Eddelbuettel [aut]


Documentation:   PDF Manual  


Task views: Web Technologies and Services


GPL (>= 2) license


Imports rvest, googleVis, zoo, ggplot2


See at CRAN