Introduction

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

The package can be installed using the following command:

devtools::install_github("PMassicotte/gtrendsR")

There are two main functions in the package: gconnect() to connect to Google using your credentials and gtrends() to perform actual queries.

library(gtrendsR)
ls("package:gtrendsR")
#> [1] "categories"  "countries"   "gconnect"    "gtrends"     "sport_trend"

Examples

In this simple example, Googling trends for keywords nhl, nba and nfl are retrieved.

Get the data

library(gtrendsR)

usr <- "user@gmail.com"
psw <- "password"

gconnect(usr, psw)

sport_trend <- gtrends(c("nhl", "nba", "nfl"))

Plot the data

## Load sample data
data("sport_trend")

plot(sport_trend)

plot of chunk unnamed-chunk-5

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

plot(sport_trend, type = "region")
plot(sport_trend, type = "cities")

Feel free to try it!