This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see http://rmarkdown.rstudio.com.
# Run once to install
install.packages(c("gtrendsR", "tidyverse", "ggplot2", "scales",
"lubridate", "knitr", "kableExtra"))
library(gtrendsR) # Pull data from Google Trends
library(tidyverse) # Data manipulation and plotting
library(ggplot2) # Visualization
library(scales) # Axis formatting
library(lubridate) # Date handling
library(knitr) # Tables
library(kableExtra) # Enhanced table formatting
“now 1-H” → Past hour “now 4-H” → Past 4 hours “today 1-m” → Past 30 days “today 3-m” → Past 90 days “today 12-m” → Past 12 months “today+5-y” → Past 5 years “all” → Since 2004
Tutorial 1: Single Keyword — Brand Search Interest
starbucks_trend <- gtrends(
keyword = "Starbucks",
geo = "US",
time = "today+5-y"
)
# Extract interest over time
iot <- starbucks_trend$interest_over_time
ggplot(iot, aes(x = date, y = hits)) +
geom_line(color = "#00704A", linewidth = 1) +
geom_smooth(method = "loess", se = TRUE, color = "#1E3932",
fill = "#D4E9E2", alpha = 0.3) +
scale_x_datetime(date_labels = "%b %Y", date_breaks = "2 months") +
labs(
title = "Google Search Interest: Starbucks",
subtitle = "United States | Past 5 years | Web Search",
x = NULL,
y = "Relative Interest (0–100)",
caption = "Source: Google Trends via gtrendsR | github.com/utjimmyx"
) +
theme_minimal(base_size = 12) +
theme(
plot.title = element_text(face = "bold", size = 14),
plot.subtitle = element_text(color = "gray50"),
axis.text.x = element_text(angle = 30, hjust = 1)
)
Google Trends. (2024). Google Trends Tutorials [YouTube series]. Google Search Central. https://developers.google.com/search/blog/2024/09/google-trends-tutorials Massicotte, P., & Eddelbuettel, D. (2023). gtrendsR: Perform and Display Google Trends Queries [R package]. https://cran.r-project.org/package=gtrendsR Chan, M. (2019). Vignette: Google Trends with the gtrendsR package. https://martinctc.github.io/blog/vignette-google-trends-with-gtrendsr/