# load libraries
library(readr)
library(tidyverse)
library(here)
burn_times <- read.csv("burn_times.csv")
purchases <- read.csv("purchases.csv")
head(burn_times)
head(purchases)
prices <- burn_times %>%
  inner_join(purchases, by = "candle_id") %>%
  select(session_time,price_usd) %>%
  group_by(price_usd) %>%
  summarize(total_time = sum(session_time))
prices
viz <- prices %>%
  arrange(price_usd) %>%
  mutate(price_usd = factor(price_usd,levels=price_usd)) %>%
  ggplot(aes(fill=total_time,x=price_usd,y=total_time)) +
  geom_bar(stat = "identity") + 
  labs(title="Burn Times by Price",x="Price (USD)",y="Total Time (Hours)")
viz

Interesting, some of less expensive candles burn for longer than the pricy ones. Especially that one that was only $20! Of course, price doesn’t tell the whole story. The weight of the candle also matters. When comparing candles, we should take both into account to get the true value proposition.

Let’s go back to the burn_times data frame and grab the weight_oz column. While we’re at it, we can do a few calculations to add up the total weight and time.

price_and_weight <- burn_times %>%
  inner_join(purchases, by = "candle_id") %>%
  select(session_time,price_usd,weight_oz) %>%
  group_by(price_usd) %>%
  transmute(price_usd = price_usd,weight_oz = weight_oz,total_time = sum(session_time)) %>%
  slice(1)
price_and_weight
price_and_weight <- price_and_weight %>%
  transmute(price_usd = price_usd, hours_per_ounce = total_time / weight_oz)
price_and_weight

Definitely seeing some interesting results now. The $20 candle, while it burned for 86 hours, did so because it was a large candle, not necessarily because it burned more efficiently. Let’s pretty things up.

viz <- price_and_weight %>%
  arrange(hours_per_ounce) %>%
  mutate(price_usd = factor(price_usd,levels=price_usd)) %>%
  ggplot(aes(fill=price_usd,x=price_usd,y=hours_per_ounce)) + geom_bar(stat = "identity") +
  theme(legend.position = "none") +
  labs(title="Hours per Ounce",x="Price",y="Hours per Ounce")
viz

Along with that 20 dollar candle, we can easily see the value proposition of the other candles. The 14 dollar candle is really doing some work!