Created
November 21, 2015 20:12
-
-
Save erzk/3a24c10be67c640d2d6a to your computer and use it in GitHub Desktop.
Query Google Trends and Google Ngrams using R
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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