Library

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)

Introduction

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/

Load Data

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

Columns Renaming & Subsetting

# 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

Create a Bar Plot

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")

Conclusion

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.