Overview

This lab analyzes Google search trends and stock price performance for coffee companies: Starbucks (SBUX), Coffee Holding Co. (JVA), and Dutch Bros (BROS). We pull live data from Google Trends and Yahoo Finance, then visualize both search interest and normalized stock performance.

# NOTE: Run the line below ONCE in your Console to install packages.
# Do NOT knit with install.packages() — it slows rendering and causes warnings.
# install.packages(c("gtrendsR", "quantmod", "lubridate", "zoo"))

library(gtrendsR)
library(quantmod)
library(lubridate)
library(zoo)

Stock Data: Pulling from Yahoo Finance

We retrieve 4 years of daily closing prices for SBUX, JVA, and BROS.

getSymbols('SBUX', src = 'yahoo',
           from = Sys.Date() - years(4), to = Sys.Date())
## [1] "SBUX"
getSymbols('JVA',  src = 'yahoo',
           from = Sys.Date() - years(4), to = Sys.Date())
## [1] "JVA"
getSymbols('BROS', src = 'yahoo',
           from = Sys.Date() - years(4), to = Sys.Date())
## [1] "BROS"
# Combine closing prices into one xts object
stocks <- as.xts(data.frame(
  SBUX = SBUX$"SBUX.Close",
  JVA  = JVA$"JVA.Close",
  BROS = BROS$"BROS.Close"
))

# Remove any rows with missing data
stocks <- na.omit(stocks)

Chart 1: Raw Closing Prices

plot(as.zoo(stocks),
     screens = 1,
     lty     = c(1, 3, 2),
     col     = c("green", "black", "blue"),
     xlab    = "Date",
     ylab    = "Closing Price (USD)",
     main    = "Coffee Stock Closing Prices (4 Years)")

legend("top",
       legend = c("SBUX", "JVA", "BROS"),
       lty    = c(1, 3, 2),
       col    = c("green", "black", "blue"),
       cex    = 0.6)

Note: SBUX trades in the $80–$110 range while JVA trades under $5, so JVA may appear nearly flat on this scale. See the normalized chart below for a fairer comparison.


Chart 2: Normalized Performance (% of Starting Price)

To compare performance fairly across different price scales, we index each stock to 100 at the start of the period.

# Normalize: each stock expressed as % of its first available price
stocks_norm <- sweep(stocks, 2, as.numeric(stocks[1, ]), FUN = "/") * 100

plot(as.zoo(stocks_norm),
     screens = 1,
     lty     = c(1, 3, 2),
     col     = c("green", "black", "blue"),
     xlab    = "Date",
     ylab    = "Price (Indexed to 100 at Start)",
     main    = "Normalized Coffee Stock Performance (4 Years)")

legend("top",
       legend = c("SBUX", "JVA", "BROS"),
       lty    = c(1, 3, 2),
       col    = c("green", "black", "blue"),
       cex    = 0.6)

A value above 100 means the stock has gained relative to its starting price; below 100 means it has lost value.


Summary

Stock Company Notes
SBUX Starbucks Corp. Large-cap; global brand
JVA Coffee Holding Co. Micro-cap; very low price per share
BROS Dutch Bros Inc. Growth-stage; IPO’d in 2021

Use the normalized chart to compare how each stock has performed relative to where it started, regardless of its absolute price.