Download and plot Google Trends data with R

December 9, 2015

(This article was first published on Revolutions, and kindly contributed to R-bloggers)

Google Trends is a useful way to compare changes in popularity of certain search terms over time, and Google Trends data can be used as a proxy for all sorts of difficult-to-measure quantities like economic activity and disease propagation. If you'd like to use Google Trends data in your own analyses, the gtrendsR package for R is now available on CRAN. This package by Philippe Massicotte and Dirk Eddelbuettel adds functions to connect with your Google account, and download Trends data for one or more search terms at daily or weekly resolution over a specified period of time.

For example, this code shows the relative prevalence of searches including the terms "data is" and "data are" over the past 10 years:

user <- ""
psw <- ""
gconnect(usr, psw)
lang_trend <- gtrends(c("data is", "data are"), res="week")

And here's the resulting plot:


In addition to the trends data (which is only useful to compare with the other terms in your query, and not for absolute popularity), the result object also includes data on the top geographic regions that requested the search terms, and the top complete queries that contained them.

You can install the gtrendsR package from CRAN, or find the latest version on GitHub.

Thinking Inside the Box: gtrends 1.3.0 now on CRAN: Google Trends in R

To leave a comment for the author, please follow the link and comment on their blog: Revolutions. offers daily e-mail updates about R news and tutorials on topics such as: Data science, Big Data, R jobs, visualization (ggplot2, Boxplots, maps, animation), programming (RStudio, Sweave, LaTeX, SQL, Eclipse, git, hadoop, Web Scraping) statistics (regression, PCA, time series, trading) and more...

If you got this far, why not subscribe for updates from the site? Choose your flavor: e-mail, twitter, RSS, or facebook...

Comments are closed.


Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)