Required Packages

# Run once if packages are not installed:
# install.packages(c("gtrendsR", "tidyverse", "ggplot2",
#                    "scales", "lubridate", "knitr", "kableExtra"))

library(gtrendsR)
library(tidyverse)
library(ggplot2)
library(scales)
library(lubridate)
library(knitr)
library(kableExtra)

Exercise 1 — Brand Tracker

Introduction

In this report, I am comparing Google search interest for three competing retail brands: Amazon, Target, and Walmart. Using Google Trends data, this analysis examines five years of U.S. web search interest, visualizes comparative trends, and identifies which brand achieved the highest search-interest peak.

Google Trends data are reported on a relative scale from 0 to 100, where 100 represents the highest level of search interest during the selected time period.

Dataset Overview

dataset_overview <- data.frame(
  Observations = nrow(iot),
  Brands = n_distinct(iot$keyword),
  Start_Date = min(iot$date),
  End_Date = max(iot$date)
)

kable(
  dataset_overview,
  caption = "Overview of Google Trends Dataset"
) %>%
  kable_styling(full_width = FALSE)
Overview of Google Trends Dataset
Observations Brands Start_Date End_Date
183 3 2020-06-01 2025-06-01

Interpretation

The dataset overview shows the number of observations, the number of brands included, and the date range covered in the analysis. This confirms that the report is comparing Amazon, Target, and Walmart over a five-year period using Google Trends search-interest data.

Comparative Trend Lines

ggplot(iot, aes(x = date, y = hits, color = keyword)) +
  geom_line(linewidth = 1) +
  scale_x_date(date_labels = "%Y", date_breaks = "1 year") +
  labs(
    title = "Google Search Interest: Amazon, Target, and Walmart",
    subtitle = "United States | Past 5 Years | Web Search",
    x = NULL,
    y = "Relative Interest (0-100)",
    color = "Brand",
    caption = "Source: Google Trends via gtrendsR"
  ) +
  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)
  )

Interpretation

The graph compares Google search interest for Amazon, Target, and Walmart in the United States over a five-year period. Amazon generally appears to have the highest level of search interest for most of the time period, which suggests that it receives more online attention compared to Target and Walmart.

All three brands show changes in search interest over time. Increases in search activity may be connected to major shopping seasons, Black Friday, Cyber Monday, holiday shopping, and promotional campaigns.

Brand with the Highest Peak

highest_peak <- iot %>%
  arrange(desc(hits)) %>%
  select(keyword, date, hits) %>%
  slice(1)

kable(
  highest_peak,
  caption = "Brand with the Highest Google Trends Peak"
) %>%
  kable_styling(full_width = FALSE)
Brand with the Highest Google Trends Peak
keyword date hits
Amazon 2022-01-01 100

Interpretation

This table identifies the brand that reached the highest search-interest value during the selected time period. The highest peak represents the strongest moment of relative public attention among the three brands.

Summary Statistics by Brand

brand_summary <- iot %>%
  group_by(keyword) %>%
  summarise(
    average_interest = round(mean(hits, na.rm = TRUE), 2),
    median_interest = round(median(hits, na.rm = TRUE), 2),
    highest_interest = max(hits, na.rm = TRUE),
    lowest_interest = min(hits, na.rm = TRUE),
    .groups = "drop"
  )

kable(
  brand_summary,
  caption = "Summary Statistics for Google Search Interest by Brand"
) %>%
  kable_styling(full_width = FALSE)
Summary Statistics for Google Search Interest by Brand
keyword average_interest median_interest highest_interest lowest_interest
Amazon 83.34 83 100 67
Target 45.89 47 65 25
Walmart 54.13 53 75 36

Interpretation

The summary statistics provide a broader comparison of Amazon, Target, and Walmart. The average and median values show typical search interest, while the highest and lowest values show the range of consumer attention each brand received during the five-year period.

Average Search Interest by Brand

ggplot(brand_summary, aes(x = keyword, y = average_interest, fill = keyword)) +
  geom_col() +
  labs(
    title = "Average Google Search Interest by Brand",
    subtitle = "United States | Past 5 Years",
    x = "Brand",
    y = "Average Relative Interest",
    caption = "Source: Google Trends via gtrendsR"
  ) +
  theme_minimal(base_size = 12) +
  theme(
    legend.position = "none",
    plot.title = element_text(face = "bold", size = 14),
    plot.subtitle = element_text(color = "gray50")
  )

Interpretation

The bar chart compares the average search interest for each brand. A higher average means that the brand maintained stronger search visibility over the full five-year period, not just during one major spike.

Seasonal Search Patterns

monthly_interest <- iot %>%
  mutate(month = month(date, label = TRUE)) %>%
  group_by(keyword, month) %>%
  summarise(
    average_interest = round(mean(hits, na.rm = TRUE), 2),
    .groups = "drop"
  )

ggplot(monthly_interest, aes(x = month, y = average_interest, color = keyword, group = keyword)) +
  geom_line(linewidth = 1) +
  geom_point(size = 2) +
  labs(
    title = "Average Monthly Search Interest",
    subtitle = "Seasonal Patterns Across Amazon, Target, and Walmart",
    x = NULL,
    y = "Average Relative Interest",
    color = "Brand",
    caption = "Source: Google Trends via gtrendsR"
  ) +
  theme_minimal(base_size = 12) +
  theme(
    plot.title = element_text(face = "bold", size = 14),
    plot.subtitle = element_text(color = "gray50")
  )

Interpretation

The seasonal graph shows how average search interest changes by month. Higher interest during certain months may suggest that consumer attention increases around shopping periods such as Black Friday, Cyber Monday, back-to-school shopping, or the holiday season.

Monthly Interest Table

kable(
  monthly_interest,
  caption = "Average Monthly Search Interest by Brand"
) %>%
  kable_styling(full_width = FALSE)
Average Monthly Search Interest by Brand
keyword month average_interest
Amazon Jan 90.40
Amazon Feb 85.20
Amazon Mar 81.60
Amazon Apr 86.60
Amazon May 81.80
Amazon Jun 87.00
Amazon Jul 83.00
Amazon Aug 73.80
Amazon Sep 76.00
Amazon Oct 80.80
Amazon Nov 87.20
Amazon Dec 86.00
Target Jan 46.80
Target Feb 42.80
Target Mar 48.00
Target Apr 43.80
Target May 46.00
Target Jun 48.17
Target Jul 55.40
Target Aug 37.80
Target Sep 46.20
Target Oct 42.80
Target Nov 42.20
Target Dec 50.20
Walmart Jan 54.20
Walmart Feb 53.80
Walmart Mar 60.00
Walmart Apr 52.60
Walmart May 51.80
Walmart Jun 60.83
Walmart Jul 56.00
Walmart Aug 50.20
Walmart Sep 57.00
Walmart Oct 51.20
Walmart Nov 46.60
Walmart Dec 54.00

Interpretation

The monthly interest table provides the numerical values behind the seasonal graph. This makes it easier to compare specific months and identify when each brand receives higher or lower average search interest.

Brand Ranking

brand_rank <- brand_summary %>%
  arrange(desc(average_interest)) %>%
  mutate(rank = row_number()) %>%
  select(rank, keyword, average_interest, highest_interest)

kable(
  brand_rank,
  caption = "Brand Ranking by Average Google Search Interest"
) %>%
  kable_styling(full_width = FALSE)
Brand Ranking by Average Google Search Interest
rank keyword average_interest highest_interest
1 Amazon 83.34 100
2 Walmart 54.13 75
3 Target 45.89 65

Interpretation

The ranking table orders the brands by average search interest. This provides a simple way to identify which retailer maintained the strongest overall level of public attention during the five-year period.

Findings

The results show that Google Trends can be used to compare public search interest across competing brands. The trend graph, summary statistics, average-interest chart, seasonal graph, and ranking table all provide different ways to understand consumer attention.

Amazon appears to have strong search interest compared to Target and Walmart. Walmart and Target also show important changes over time, especially during seasonal shopping periods. These patterns suggest that retail search interest is influenced by promotions, holidays, and major shopping events.

It is important to note that Google Trends measures relative search interest rather than the actual number of searches. Therefore, the results should be viewed as a measure of public interest and attention rather than exact search volume.

Conclusion

This analysis demonstrates how Google Trends can be used to compare consumer interest in competing brands over time. By examining Amazon, Target, and Walmart, it is possible to identify patterns in search behavior and observe how consumer attention changes throughout the year.

The results suggest that major shopping events and promotional campaigns have a strong impact on search interest. Understanding these trends can help businesses and marketing professionals plan advertising campaigns, anticipate trends, and make more informed decisions.

References

Google Trends. (2024). Google Trends Tutorials. Google Search Central. Available at: 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]. Available at: https://cran.r-project.org/package=gtrendsR

Chan, M. (2019). Google Trends with the gtrendsR Package. Available at: https://martinctc.github.io/blog/vignette-google-trends-with-gtrendsr/