library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr 1.1.4 ✔ readr 2.1.5
## ✔ forcats 1.0.0 ✔ stringr 1.5.1
## ✔ ggplot2 3.5.1 ✔ tibble 3.2.1
## ✔ lubridate 1.9.3 ✔ tidyr 1.3.1
## ✔ purrr 1.0.2
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag() masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(dplyr)
library(ggplot2)
The article I chose from FiveThirtyEight was “The Ultimate Halloween Candy Power Ranking,” published on October 31, 2016. The article presents a ranking based on survey, sales data, and other metrics, providing insights into which treats are most favored during the Halloween season.
The dataset was taken from: https://fivethirtyeight.com/videos/the-ultimate-halloween-candy-power-ranking/
candy_rawdata <- read.csv("https://raw.githubusercontent.com/JaydeeJan/Best-Candy/refs/heads/main/candy-data.csv")
head(candy_rawdata)
## competitorname chocolate fruity caramel peanutyalmondy nougat
## 1 100 Grand 1 0 1 0 0
## 2 3 Musketeers 1 0 0 0 1
## 3 One dime 0 0 0 0 0
## 4 One quarter 0 0 0 0 0
## 5 Air Heads 0 1 0 0 0
## 6 Almond Joy 1 0 0 1 0
## crispedricewafer hard bar pluribus sugarpercent pricepercent winpercent
## 1 1 0 1 0 0.732 0.860 66.97173
## 2 0 0 1 0 0.604 0.511 67.60294
## 3 0 0 0 0 0.011 0.116 32.26109
## 4 0 0 0 0 0.011 0.511 46.11650
## 5 0 0 0 0 0.906 0.511 52.34146
## 6 0 0 1 0 0.465 0.767 50.34755
# rename
candy_rawdata <- candy_rawdata %>%
rename(
Candy_Name = competitorname,
Chocolate = chocolate,
Fruity = fruity,
Caramel = caramel,
Peanut_Almond = peanutyalmondy,
Nougat = nougat,
Crisped_Rice_Wafer = crispedricewafer,
Hard = hard,
Bar = bar,
Sugar_Percentage = sugarpercent,
Price_Percentage = pricepercent,
Win_Percentage = winpercent
)
# subset
candy_subsetdata <- candy_rawdata %>%
select(
Candy_Name, Chocolate, Fruity, Caramel, Peanut_Almond, Nougat, Crisped_Rice_Wafer, Hard, Bar, Sugar_Percentage, Price_Percentage, Win_Percentage
)
head(candy_subsetdata)
## Candy_Name Chocolate Fruity Caramel Peanut_Almond Nougat Crisped_Rice_Wafer
## 1 100 Grand 1 0 1 0 0 1
## 2 3 Musketeers 1 0 0 0 1 0
## 3 One dime 0 0 0 0 0 0
## 4 One quarter 0 0 0 0 0 0
## 5 Air Heads 0 1 0 0 0 0
## 6 Almond Joy 1 0 0 1 0 0
## Hard Bar Sugar_Percentage Price_Percentage Win_Percentage
## 1 0 1 0.732 0.860 66.97173
## 2 0 1 0.604 0.511 67.60294
## 3 0 0 0.011 0.116 32.26109
## 4 0 0 0.011 0.511 46.11650
## 5 0 0 0.906 0.511 52.34146
## 6 0 1 0.465 0.767 50.34755
top_10_candy <- candy_subsetdata %>%
arrange(desc(Win_Percentage)) %>%
head(10)
top_10_candy
## Candy_Name Chocolate Fruity Caramel Peanut_Almond Nougat
## 1 Reese's Peanut Butter cup 1 0 0 1 0
## 2 Reese's Miniatures 1 0 0 1 0
## 3 Twix 1 0 1 0 0
## 4 Kit Kat 1 0 0 0 0
## 5 Snickers 1 0 1 1 1
## 6 Reese's pieces 1 0 0 1 0
## 7 Milky Way 1 0 1 0 1
## 8 Reese's stuffed with pieces 1 0 0 1 0
## 9 Peanut butter M&M's 1 0 0 1 0
## 10 Nestle Butterfinger 1 0 0 1 0
## Crisped_Rice_Wafer Hard Bar Sugar_Percentage Price_Percentage Win_Percentage
## 1 0 0 0 0.720 0.651 84.18029
## 2 0 0 0 0.034 0.279 81.86626
## 3 1 0 1 0.546 0.906 81.64291
## 4 1 0 1 0.313 0.511 76.76860
## 5 0 0 1 0.546 0.651 76.67378
## 6 0 0 0 0.406 0.651 73.43499
## 7 0 0 1 0.604 0.651 73.09956
## 8 0 0 0 0.988 0.651 72.88790
## 9 0 0 0 0.825 0.651 71.46505
## 10 0 0 1 0.604 0.767 70.73564
ggplot(top_10_candy, aes(x = reorder(Candy_Name, Win_Percentage), y = Win_Percentage, fill = Candy_Name)) +
geom_bar(stat = "identity") +
coord_flip() +
labs(
title = "Top 10 Hallowwen Candies rated by Win Percentage",
x = "Candy Name",
y = "Win Percentage"
) +
theme_minimal() +
theme(legend.position = "none")
The retailers and manufactureers should focus more on promoting chocolate and peanut-based candies during Halloween season based from graph above. Offering differient packs containing both with and without peanut chocolate may maximum the profit sales.