Analyse Google Trends Search Data in R using {gtrendsR}

[This article was first published on r-bloggers on Programming with R, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

As much as Google is popular for searching information on the web, Google can also provide information (meta) about those searches. Google Search Insights can be extremely helpful in Marketing Analytics, Market Research, Understanding Customer Demands, Trends and so on. While usual Market Researches or someone interested in Google Search Information would go to Google Trends website, Being a programmer you can extract the same information programmatically to use in your Data Science Workflow or to set up an Automation.

In this video, We go through how to use the R package {gtrendsR} to analyse Google Trends Search Data.

Youtube: https://www.youtube.com/watch?v=xbLJNARUyT0

Code

library(gtrendsR)
library(tidyverse)


res <- gtrends(c("zoom", "slack"))

iot <- res$interest_over_time

iot2020 <- iot %>% 
  filter(date > as.Date("2020-01-01"))

iot2020 %>% 
  ggplot() + geom_line(aes(x = date,
                           y = hits,
                           color = keyword)) +
  theme_minimal() +
  labs(title = "Zoom vs Slack - in 2020",
       subtitle = "Google Trends Report",
       caption = "Courtesy: gtrendsR package")

library(gtrendsR)
library(dplyr)

## 
## Attaching package: 'dplyr'

## The following objects are masked from 'package:stats':
## 
##     filter, lag

## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union

library(ggplot2)


res <- gtrends(c("zoom", "slack"))

iot <- res$interest_over_time

iot2020 <- iot %>% 
  filter(date > as.Date("2020-01-01"))

## Warning in mask$eval_all_filter(dots, env_filter): Incompatible methods
## ("Ops.POSIXt", "Ops.Date") for ">"

iot2020 %>% 
  ggplot() + geom_line(aes(x = date,
                           y = hits,
                           color = keyword)) +
  theme_minimal() +
  labs(title = "Zoom vs Slack - in 2020",
       subtitle = "Google Trends Report",
       caption = "Courtesy: gtrendsR package")

Please raise a github issue if you find any difficulties and let me know your feedback if you have any comments!

To leave a comment for the author, please follow the link and comment on their blog: r-bloggers on Programming with R.

R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)