This article shows with example how to analyze Google Trends data in R programming languages. The R package gtrendsR is used in this article for analyzing the google trends data.
The
gtrendsR
Package
The gtrendsR Package is built for retrieving and displaying the information from Google Trends.
Let's install and load the package:
install.packages("gtrendsR")
library(gtrendsR)
Now, let's check the main arguments of the package:
- keyword: A character vector for specifying query keywords. For example, c("python", "java")
- geo: A character vector of geographic regions. For example, c("ES") (default value is "all" for worldwide).
- time: A string for specifying the time span of the query. For example, "now 3-H" (last three hours), "now 7-d" (last seven days), "today 3-m" (last three months), "today+5-y" (last five years) (default value), "all" (all since 2004), or 2015-01-01 2016-12-30 (time span between two dates).
- gprop: A character vector for specifying Google product or service to perform trend query. For example, c("web", "news", "images", "froogle", "youtube") (default value is "web").
- category: A character for specifying the character (default value is "0").
- hl: A string for specifying language code. For example, "es-ES" (default value is "en-US")
- lower_search_volume: A logical value for specifying whether to include lower search volume regions or not.
Google Trends Analysis Example
Let's compare Python and Java in Google Trends for the last five years over the world, and see the relative interest over time between them in a plot.
library(gtrendsR)
library(tidyverse)
trends <- gtrends(keyword = c("python", "java"))
# select only interest over time
time_trend <- trends$interest_over_time
# display the plot
plot_line <- ggplot(data = time_trend, aes(x = date, y = hits, color = keyword)) +
geom_line() +
labs(title = "Python vs Java",
subtitle = "A Google Trends Report",
x = "Time",
y = "Relative Interest")
plot_line
Ending note
Hope, this will help you to explore Google Trends data analysis in R using gtrendsR Package.
Happy R coding!
Comments
You are welcome to write comments, suggestions, corrections, or any queries related to the article. Your comments may take some time to be appeared. Please be aware that any irrelevant comments will be deleted. Thanks for your understanding, and your respectful & relevant comments!