OVERVIEW The Data I will be working with for this assignment is halloween candy power ranking, i will show which type of candy has the highest percentage of winning. my data was taken from https://github.com/fivethirtyeight/data/tree/master/candy-power-ranking

library(dplyr)
## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
library(knitr)
library(readr)
library(ggplot2)
options(readr.show_col_types = FALSE)

Loading Data from github file

Candy <- "https://raw.githubusercontent.com/MRobinson112/data_607_assignment-1/main/candy-data.csv"
candy_data <- read_csv(Candy)

head(candy_data)

Renaming a few columns

candy_data <- candy_data %>%
  rename(
    CandyName = competitorname,
    Chocolate = chocolate,
    WinPercent = winpercent
  )
head(candy_data)

Changing the values in the chocolate column from 1’s or 0’s to “Yes” or “No”

candy_data$Chocolate <- ifelse(candy_data$Chocolate, "Yes", "No")
head(candy_data)

Selecting relevant columns for camparison

candy_subset <- candy_data %>%
  select(CandyName, Chocolate, WinPercent)

Creating a chart comparing chocolate win percent to candy without chocolate

ggplot(candy_subset, aes(x = Chocolate, y = WinPercent, fill = Chocolate)) +
  geom_boxplot() +
  labs(
    title = "Comparison of Chocolate vs. Non-Chocolate Candy Win Percent",
    x = "Contains Chocolate",
    y = "Win Percent"
  ) +
  theme_minimal()

# Conclusion: Candies that contains chocolate has the highest percentage of winning.

candy_subset %>%
   knitr::kable(caption = "Subset table")
Subset table
CandyName Chocolate WinPercent
100 Grand Yes 66.97173
3 Musketeers Yes 67.60294
One dime No 32.26109
One quarter No 46.11650
Air Heads No 52.34146
Almond Joy Yes 50.34755
Baby Ruth Yes 56.91455
Boston Baked Beans No 23.41782
Candy Corn No 38.01096
Caramel Apple Pops No 34.51768
Charleston Chew Yes 38.97504
Chewey Lemonhead Fruit Mix No 36.01763
Chiclets No 24.52499
Dots No 42.27208
Dum Dums No 39.46056
Fruit Chews No 43.08892
Fun Dip No 39.18550
Gobstopper No 46.78335
Haribo Gold Bears No 57.11974
Haribo Happy Cola No 34.15896
Haribo Sour Bears No 51.41243
Haribo Twin Snakes No 42.17877
Hershey’s Kisses Yes 55.37545
Hershey’s Krackel Yes 62.28448
Hershey’s Milk Chocolate Yes 56.49050
Hershey’s Special Dark Yes 59.23612
Jawbusters No 28.12744
Junior Mints Yes 57.21925
Kit Kat Yes 76.76860
Laffy Taffy No 41.38956
Lemonhead No 39.14106
Lifesavers big ring gummies No 52.91139
Peanut butter M&M’s Yes 71.46505
M&M’s Yes 66.57458
Mike & Ike No 46.41172
Milk Duds Yes 55.06407
Milky Way Yes 73.09956
Milky Way Midnight Yes 60.80070
Milky Way Simply Caramel Yes 64.35334
Mounds Yes 47.82975
Mr Good Bar Yes 54.52645
Nerds No 55.35405
Nestle Butterfinger Yes 70.73564
Nestle Crunch Yes 66.47068
Nik L Nip No 22.44534
Now & Later No 39.44680
Payday No 46.29660
Peanut M&Ms Yes 69.48379
Pixie Sticks No 37.72234
Pop Rocks No 41.26551
Red vines No 37.34852
Reese’s Miniatures Yes 81.86626
Reese’s Peanut Butter cup Yes 84.18029
Reese’s pieces Yes 73.43499
Reese’s stuffed with pieces Yes 72.88790
Ring pop No 35.29076
Rolo Yes 65.71629
Root Beer Barrels No 29.70369
Runts No 42.84914
Sixlets Yes 34.72200
Skittles original No 63.08514
Skittles wildberry No 55.10370
Nestle Smarties Yes 37.88719
Smarties candy No 45.99583
Snickers Yes 76.67378
Snickers Crisper Yes 59.52925
Sour Patch Kids No 59.86400
Sour Patch Tricksters No 52.82595
Starburst No 67.03763
Strawberry bon bons No 34.57899
Sugar Babies No 33.43755
Sugar Daddy No 32.23100
Super Bubble No 27.30386
Swedish Fish No 54.86111
Tootsie Pop Yes 48.98265
Tootsie Roll Juniors Yes 43.06890
Tootsie Roll Midgies Yes 45.73675
Tootsie Roll Snack Bars Yes 49.65350
Trolli Sour Bites No 47.17323
Twix Yes 81.64291
Twizzlers No 45.46628
Warheads No 39.01190
Welch’s Fruit Snacks No 44.37552
Werther’s Original Caramel No 41.90431
Whoppers Yes 49.52411