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:
library(gtrendsR)
usr <- "<Google account email>"
psw <- "<Google account password>"
gconnect(usr, psw)
lang_trend <- gtrends(c("data is", "data are"), res="week")
plot(lang_trend)
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
Thanks for sharing David. This is great!
Small code error with 'user' and 'usr' though.
Here's a quick first-year indexing to flip the takeaway:
lang_trend$trend[,3]<-lang_trend$trend[,3]/mean(lang_trend$trend[1:52,3])
lang_trend$trend[,4]<-lang_trend$trend[,4]/mean(lang_trend$trend[1:52,4])
plot(lang_trend)
Posted by: RetailSci | December 09, 2015 at 16:57
When I send your exact query, or any other, I get:
Error: Not enough search volume. Please change your search terms.
What does that mean? Thanks
Posted by: Wayne Gray | December 11, 2015 at 06:50
Hi David,
thank you for sharing but unfortunately do not work the function on my system (OS Windows 10, R64 3.2.2)! I get following message (different binary versions of binary/source):
Es gibt eine Binärversion, jedoch ist der Quelltext neuer:
binary source needs_compilation
gtrendsR 1.3.0 1.3.1 FALSE
installing the source package ‘gtrendsR’
.
.
.
* installing *source* package 'gtrendsR' ...
** Paket 'gtrendsR' erfolgreich entpackt und MD5 Summen überprüft
Warnung in file(file, ifelse(append, "a", "w"))
kann Datei 'C:/Users/G|nter/Documents/R/win-library/3.2/gtrendsR/DESCRIPTION' nicht öffnen: Invalid argument
Error in file(file, ifelse(append, "a", "w")) :
kann Verbindung nicht öffnen
ERROR: installing package DESCRIPTION failed for package 'gtrendsR'
* removing 'C:/Users/Günter/Documents/R/win-library/3.2/gtrendsR'
.
.
Do you have any hint?
Best regards,
Guenter
Posted by: Günter Faes | December 13, 2015 at 01:11
David, thanks for answering my #1 English usage question! I should have thought of this. Cheers, Bob
Posted by: BobMuenchen | December 15, 2015 at 04:58