Skip to content

Instantly share code, notes, and snippets.

@erzk
Created November 21, 2015 20:12
Embed
What would you like to do?
Query Google Trends and Google Ngrams using R
# install necessary packages
devtools::install_github("dvanclev/GTrendsR")
devtools::install_github("trinker/gtrend")
# load the packages
library(curl)
library(dplyr)
library(gtrend)
library(ggplot2)
library(ngramr)
# query Google Ngrams and create a plot
ngramData <- ngrami(c("Sigmund Freud", "Carl Jung"), year_start = 1900)
ggplot(ngramData,
aes(Year, Frequency, colour = Phrase)) +
geom_line(lwd = 1) +
stat_smooth()
# query Google Trends
gtrendQueries <- c("Sigmund Freud", "Carl Jung")
# add your Google account details
outputGT <- gtrend_scraper("YOUR EMAIL", "YOUR PASSWORD", gtrendQueries)
# create a plot
outputGT %>%
trend2long() %>%
plot() +
stat_smooth()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment