Google Trends with R statsLee Hawthorn June 04, 2019 #R
There's a new package on CRAN that makes it easier to consume Google Trend data.
The package to use is
There are a couple of API's in this package but the interesting one is to compare the terms that are searched :
trendy(). It's based on
gtrendsR so you can pass through any arguments you need.
gtrends documentation on cran
trendyy documentation on cran
You need to pass in a vector of terms (5 max).
You can then process it with
In the code below I've added some GGMAP code to plot the interest over time. I've restricted the search to GB too but not sure how reliable this is.
Code to produce this chart is listed below. All packages used here are on CRAN. I used GNU R 3.6.0.
require("magrittr") require("dplyr") require("ggplot2") require("trendyy") terms <- c("Boris Johnson", "Dominic Raab", "Jeremy Hunt", "Rory Stewart") terms_trends <- trendy(terms, from = "2019-05-01", to = Sys.Date(), geo = c("GB")) terms_trends %>% get_interest() %>% ggplot(aes(date, hits, color = keyword)) + geom_line() + geom_point(alpha = .2) + theme_minimal() + theme(legend.position = "bottom") + labs(x = "", y = "Relative Search Popularity", title = "Google Search Popularity")
I'll leave it to you to draw any conclusions.