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)
Introdaction:
The article discusses the social contract of Halloween and an experiment that pits different fun-sized candy types against each other to determine people’s preferences. It highlights the factors that contribute to a candy’s desirability, such as ingredients and the impact of chocolate, nuts, crispiness, nougat, and caramel on a candy’s win percentage.
https://fivethirtyeight.com/videos/the-ultimate-halloween-candy-power-ranking/
candy_data <- read.csv("https://raw.githubusercontent.com/tonyCUNY/tonyCUNY/main/candy-data.csv")
as.data.frame(candy_data)
## 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
## 7 Baby Ruth 1 0 1 1 1
## 8 Boston Baked Beans 0 0 0 1 0
## 9 Candy Corn 0 0 0 0 0
## 10 Caramel Apple Pops 0 1 1 0 0
## 11 Charleston Chew 1 0 0 0 1
## 12 Chewey Lemonhead Fruit Mix 0 1 0 0 0
## 13 Chiclets 0 1 0 0 0
## 14 Dots 0 1 0 0 0
## 15 Dum Dums 0 1 0 0 0
## 16 Fruit Chews 0 1 0 0 0
## 17 Fun Dip 0 1 0 0 0
## 18 Gobstopper 0 1 0 0 0
## 19 Haribo Gold Bears 0 1 0 0 0
## 20 Haribo Happy Cola 0 0 0 0 0
## 21 Haribo Sour Bears 0 1 0 0 0
## 22 Haribo Twin Snakes 0 1 0 0 0
## 23 Hershey's Kisses 1 0 0 0 0
## 24 Hershey's Krackel 1 0 0 0 0
## 25 Hershey's Milk Chocolate 1 0 0 0 0
## 26 Hershey's Special Dark 1 0 0 0 0
## 27 Jawbusters 0 1 0 0 0
## 28 Junior Mints 1 0 0 0 0
## 29 Kit Kat 1 0 0 0 0
## 30 Laffy Taffy 0 1 0 0 0
## 31 Lemonhead 0 1 0 0 0
## 32 Lifesavers big ring gummies 0 1 0 0 0
## 33 Peanut butter M&M's 1 0 0 1 0
## 34 M&M's 1 0 0 0 0
## 35 Mike & Ike 0 1 0 0 0
## 36 Milk Duds 1 0 1 0 0
## 37 Milky Way 1 0 1 0 1
## 38 Milky Way Midnight 1 0 1 0 1
## 39 Milky Way Simply Caramel 1 0 1 0 0
## 40 Mounds 1 0 0 0 0
## 41 Mr Good Bar 1 0 0 1 0
## 42 Nerds 0 1 0 0 0
## 43 Nestle Butterfinger 1 0 0 1 0
## 44 Nestle Crunch 1 0 0 0 0
## 45 Nik L Nip 0 1 0 0 0
## 46 Now & Later 0 1 0 0 0
## 47 Payday 0 0 0 1 1
## 48 Peanut M&Ms 1 0 0 1 0
## 49 Pixie Sticks 0 0 0 0 0
## 50 Pop Rocks 0 1 0 0 0
## 51 Red vines 0 1 0 0 0
## 52 Reese's Miniatures 1 0 0 1 0
## 53 Reese's Peanut Butter cup 1 0 0 1 0
## 54 Reese's pieces 1 0 0 1 0
## 55 Reese's stuffed with pieces 1 0 0 1 0
## 56 Ring pop 0 1 0 0 0
## 57 Rolo 1 0 1 0 0
## 58 Root Beer Barrels 0 0 0 0 0
## 59 Runts 0 1 0 0 0
## 60 Sixlets 1 0 0 0 0
## 61 Skittles original 0 1 0 0 0
## 62 Skittles wildberry 0 1 0 0 0
## 63 Nestle Smarties 1 0 0 0 0
## 64 Smarties candy 0 1 0 0 0
## 65 Snickers 1 0 1 1 1
## 66 Snickers Crisper 1 0 1 1 0
## 67 Sour Patch Kids 0 1 0 0 0
## 68 Sour Patch Tricksters 0 1 0 0 0
## 69 Starburst 0 1 0 0 0
## 70 Strawberry bon bons 0 1 0 0 0
## 71 Sugar Babies 0 0 1 0 0
## 72 Sugar Daddy 0 0 1 0 0
## 73 Super Bubble 0 1 0 0 0
## 74 Swedish Fish 0 1 0 0 0
## 75 Tootsie Pop 1 1 0 0 0
## 76 Tootsie Roll Juniors 1 0 0 0 0
## 77 Tootsie Roll Midgies 1 0 0 0 0
## 78 Tootsie Roll Snack Bars 1 0 0 0 0
## 79 Trolli Sour Bites 0 1 0 0 0
## 80 Twix 1 0 1 0 0
## 81 Twizzlers 0 1 0 0 0
## 82 Warheads 0 1 0 0 0
## 83 Welch's Fruit Snacks 0 1 0 0 0
## 84 Werther's Original Caramel 0 0 1 0 0
## 85 Whoppers 1 0 0 0 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
## 7 0 0 1 0 0.604 0.767 56.91455
## 8 0 0 0 1 0.313 0.511 23.41782
## 9 0 0 0 1 0.906 0.325 38.01096
## 10 0 0 0 0 0.604 0.325 34.51768
## 11 0 0 1 0 0.604 0.511 38.97504
## 12 0 0 0 1 0.732 0.511 36.01763
## 13 0 0 0 1 0.046 0.325 24.52499
## 14 0 0 0 1 0.732 0.511 42.27208
## 15 0 1 0 0 0.732 0.034 39.46056
## 16 0 0 0 1 0.127 0.034 43.08892
## 17 0 1 0 0 0.732 0.325 39.18550
## 18 0 1 0 1 0.906 0.453 46.78335
## 19 0 0 0 1 0.465 0.465 57.11974
## 20 0 0 0 1 0.465 0.465 34.15896
## 21 0 0 0 1 0.465 0.465 51.41243
## 22 0 0 0 1 0.465 0.465 42.17877
## 23 0 0 0 1 0.127 0.093 55.37545
## 24 1 0 1 0 0.430 0.918 62.28448
## 25 0 0 1 0 0.430 0.918 56.49050
## 26 0 0 1 0 0.430 0.918 59.23612
## 27 0 1 0 1 0.093 0.511 28.12744
## 28 0 0 0 1 0.197 0.511 57.21925
## 29 1 0 1 0 0.313 0.511 76.76860
## 30 0 0 0 0 0.220 0.116 41.38956
## 31 0 1 0 0 0.046 0.104 39.14106
## 32 0 0 0 0 0.267 0.279 52.91139
## 33 0 0 0 1 0.825 0.651 71.46505
## 34 0 0 0 1 0.825 0.651 66.57458
## 35 0 0 0 1 0.872 0.325 46.41172
## 36 0 0 0 1 0.302 0.511 55.06407
## 37 0 0 1 0 0.604 0.651 73.09956
## 38 0 0 1 0 0.732 0.441 60.80070
## 39 0 0 1 0 0.965 0.860 64.35334
## 40 0 0 1 0 0.313 0.860 47.82975
## 41 0 0 1 0 0.313 0.918 54.52645
## 42 0 1 0 1 0.848 0.325 55.35405
## 43 0 0 1 0 0.604 0.767 70.73564
## 44 1 0 1 0 0.313 0.767 66.47068
## 45 0 0 0 1 0.197 0.976 22.44534
## 46 0 0 0 1 0.220 0.325 39.44680
## 47 0 0 1 0 0.465 0.767 46.29660
## 48 0 0 0 1 0.593 0.651 69.48379
## 49 0 0 0 1 0.093 0.023 37.72234
## 50 0 1 0 1 0.604 0.837 41.26551
## 51 0 0 0 1 0.581 0.116 37.34852
## 52 0 0 0 0 0.034 0.279 81.86626
## 53 0 0 0 0 0.720 0.651 84.18029
## 54 0 0 0 1 0.406 0.651 73.43499
## 55 0 0 0 0 0.988 0.651 72.88790
## 56 0 1 0 0 0.732 0.965 35.29076
## 57 0 0 0 1 0.860 0.860 65.71629
## 58 0 1 0 1 0.732 0.069 29.70369
## 59 0 1 0 1 0.872 0.279 42.84914
## 60 0 0 0 1 0.220 0.081 34.72200
## 61 0 0 0 1 0.941 0.220 63.08514
## 62 0 0 0 1 0.941 0.220 55.10370
## 63 0 0 0 1 0.267 0.976 37.88719
## 64 0 1 0 1 0.267 0.116 45.99583
## 65 0 0 1 0 0.546 0.651 76.67378
## 66 1 0 1 0 0.604 0.651 59.52925
## 67 0 0 0 1 0.069 0.116 59.86400
## 68 0 0 0 1 0.069 0.116 52.82595
## 69 0 0 0 1 0.151 0.220 67.03763
## 70 0 1 0 1 0.569 0.058 34.57899
## 71 0 0 0 1 0.965 0.767 33.43755
## 72 0 0 0 0 0.418 0.325 32.23100
## 73 0 0 0 0 0.162 0.116 27.30386
## 74 0 0 0 1 0.604 0.755 54.86111
## 75 0 1 0 0 0.604 0.325 48.98265
## 76 0 0 0 0 0.313 0.511 43.06890
## 77 0 0 0 1 0.174 0.011 45.73675
## 78 0 0 1 0 0.465 0.325 49.65350
## 79 0 0 0 1 0.313 0.255 47.17323
## 80 1 0 1 0 0.546 0.906 81.64291
## 81 0 0 0 0 0.220 0.116 45.46628
## 82 0 1 0 0 0.093 0.116 39.01190
## 83 0 0 0 1 0.313 0.313 44.37552
## 84 0 1 0 0 0.186 0.267 41.90431
## 85 1 0 0 1 0.872 0.848 49.52411
glimpse(candy_data)
## Rows: 85
## Columns: 13
## $ competitorname <chr> "100 Grand", "3 Musketeers", "One dime", "One quarter…
## $ chocolate <int> 1, 1, 0, 0, 0, 1, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0,…
## $ fruity <int> 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1,…
## $ caramel <int> 1, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0,…
## $ peanutyalmondy <int> 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,…
## $ nougat <int> 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0,…
## $ crispedricewafer <int> 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,…
## $ hard <int> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 1,…
## $ bar <int> 1, 1, 0, 0, 0, 1, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0,…
## $ pluribus <int> 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 1, 1, 1, 0, 1, 0, 1,…
## $ sugarpercent <dbl> 0.732, 0.604, 0.011, 0.011, 0.906, 0.465, 0.604, 0.31…
## $ pricepercent <dbl> 0.860, 0.511, 0.116, 0.511, 0.511, 0.767, 0.767, 0.51…
## $ winpercent <dbl> 66.97173, 67.60294, 32.26109, 46.11650, 52.34146, 50.…
ggplot(data = candy_data, aes(x = competitorname, y = winpercent)) + geom_point()
ggplot(data = candy_data, aes(x = competitorname, y = sugarpercent)) + geom_point()
ggplot(data = candy_data, aes(x = competitorname, y = pricepercent)) + geom_point()
ggplot(data = candy_data, aes(x = sugarpercent, y = pricepercent)) + geom_line()
ggplot(data = candy_data, aes(x = winpercent, y = pricepercent)) + geom_line()
desc_candy <- candy_data %>% arrange(desc(winpercent))
desc_candy
## competitorname chocolate fruity caramel peanutyalmondy 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
## 11 Peanut M&Ms 1 0 0 1 0
## 12 3 Musketeers 1 0 0 0 1
## 13 Starburst 0 1 0 0 0
## 14 100 Grand 1 0 1 0 0
## 15 M&M's 1 0 0 0 0
## 16 Nestle Crunch 1 0 0 0 0
## 17 Rolo 1 0 1 0 0
## 18 Milky Way Simply Caramel 1 0 1 0 0
## 19 Skittles original 0 1 0 0 0
## 20 Hershey's Krackel 1 0 0 0 0
## 21 Milky Way Midnight 1 0 1 0 1
## 22 Sour Patch Kids 0 1 0 0 0
## 23 Snickers Crisper 1 0 1 1 0
## 24 Hershey's Special Dark 1 0 0 0 0
## 25 Junior Mints 1 0 0 0 0
## 26 Haribo Gold Bears 0 1 0 0 0
## 27 Baby Ruth 1 0 1 1 1
## 28 Hershey's Milk Chocolate 1 0 0 0 0
## 29 Hershey's Kisses 1 0 0 0 0
## 30 Nerds 0 1 0 0 0
## 31 Skittles wildberry 0 1 0 0 0
## 32 Milk Duds 1 0 1 0 0
## 33 Swedish Fish 0 1 0 0 0
## 34 Mr Good Bar 1 0 0 1 0
## 35 Lifesavers big ring gummies 0 1 0 0 0
## 36 Sour Patch Tricksters 0 1 0 0 0
## 37 Air Heads 0 1 0 0 0
## 38 Haribo Sour Bears 0 1 0 0 0
## 39 Almond Joy 1 0 0 1 0
## 40 Tootsie Roll Snack Bars 1 0 0 0 0
## 41 Whoppers 1 0 0 0 0
## 42 Tootsie Pop 1 1 0 0 0
## 43 Mounds 1 0 0 0 0
## 44 Trolli Sour Bites 0 1 0 0 0
## 45 Gobstopper 0 1 0 0 0
## 46 Mike & Ike 0 1 0 0 0
## 47 Payday 0 0 0 1 1
## 48 One quarter 0 0 0 0 0
## 49 Smarties candy 0 1 0 0 0
## 50 Tootsie Roll Midgies 1 0 0 0 0
## 51 Twizzlers 0 1 0 0 0
## 52 Welch's Fruit Snacks 0 1 0 0 0
## 53 Fruit Chews 0 1 0 0 0
## 54 Tootsie Roll Juniors 1 0 0 0 0
## 55 Runts 0 1 0 0 0
## 56 Dots 0 1 0 0 0
## 57 Haribo Twin Snakes 0 1 0 0 0
## 58 Werther's Original Caramel 0 0 1 0 0
## 59 Laffy Taffy 0 1 0 0 0
## 60 Pop Rocks 0 1 0 0 0
## 61 Dum Dums 0 1 0 0 0
## 62 Now & Later 0 1 0 0 0
## 63 Fun Dip 0 1 0 0 0
## 64 Lemonhead 0 1 0 0 0
## 65 Warheads 0 1 0 0 0
## 66 Charleston Chew 1 0 0 0 1
## 67 Candy Corn 0 0 0 0 0
## 68 Nestle Smarties 1 0 0 0 0
## 69 Pixie Sticks 0 0 0 0 0
## 70 Red vines 0 1 0 0 0
## 71 Chewey Lemonhead Fruit Mix 0 1 0 0 0
## 72 Ring pop 0 1 0 0 0
## 73 Sixlets 1 0 0 0 0
## 74 Strawberry bon bons 0 1 0 0 0
## 75 Caramel Apple Pops 0 1 1 0 0
## 76 Haribo Happy Cola 0 0 0 0 0
## 77 Sugar Babies 0 0 1 0 0
## 78 One dime 0 0 0 0 0
## 79 Sugar Daddy 0 0 1 0 0
## 80 Root Beer Barrels 0 0 0 0 0
## 81 Jawbusters 0 1 0 0 0
## 82 Super Bubble 0 1 0 0 0
## 83 Chiclets 0 1 0 0 0
## 84 Boston Baked Beans 0 0 0 1 0
## 85 Nik L Nip 0 1 0 0 0
## crispedricewafer hard bar pluribus sugarpercent pricepercent winpercent
## 1 0 0 0 0 0.720 0.651 84.18029
## 2 0 0 0 0 0.034 0.279 81.86626
## 3 1 0 1 0 0.546 0.906 81.64291
## 4 1 0 1 0 0.313 0.511 76.76860
## 5 0 0 1 0 0.546 0.651 76.67378
## 6 0 0 0 1 0.406 0.651 73.43499
## 7 0 0 1 0 0.604 0.651 73.09956
## 8 0 0 0 0 0.988 0.651 72.88790
## 9 0 0 0 1 0.825 0.651 71.46505
## 10 0 0 1 0 0.604 0.767 70.73564
## 11 0 0 0 1 0.593 0.651 69.48379
## 12 0 0 1 0 0.604 0.511 67.60294
## 13 0 0 0 1 0.151 0.220 67.03763
## 14 1 0 1 0 0.732 0.860 66.97173
## 15 0 0 0 1 0.825 0.651 66.57458
## 16 1 0 1 0 0.313 0.767 66.47068
## 17 0 0 0 1 0.860 0.860 65.71629
## 18 0 0 1 0 0.965 0.860 64.35334
## 19 0 0 0 1 0.941 0.220 63.08514
## 20 1 0 1 0 0.430 0.918 62.28448
## 21 0 0 1 0 0.732 0.441 60.80070
## 22 0 0 0 1 0.069 0.116 59.86400
## 23 1 0 1 0 0.604 0.651 59.52925
## 24 0 0 1 0 0.430 0.918 59.23612
## 25 0 0 0 1 0.197 0.511 57.21925
## 26 0 0 0 1 0.465 0.465 57.11974
## 27 0 0 1 0 0.604 0.767 56.91455
## 28 0 0 1 0 0.430 0.918 56.49050
## 29 0 0 0 1 0.127 0.093 55.37545
## 30 0 1 0 1 0.848 0.325 55.35405
## 31 0 0 0 1 0.941 0.220 55.10370
## 32 0 0 0 1 0.302 0.511 55.06407
## 33 0 0 0 1 0.604 0.755 54.86111
## 34 0 0 1 0 0.313 0.918 54.52645
## 35 0 0 0 0 0.267 0.279 52.91139
## 36 0 0 0 1 0.069 0.116 52.82595
## 37 0 0 0 0 0.906 0.511 52.34146
## 38 0 0 0 1 0.465 0.465 51.41243
## 39 0 0 1 0 0.465 0.767 50.34755
## 40 0 0 1 0 0.465 0.325 49.65350
## 41 1 0 0 1 0.872 0.848 49.52411
## 42 0 1 0 0 0.604 0.325 48.98265
## 43 0 0 1 0 0.313 0.860 47.82975
## 44 0 0 0 1 0.313 0.255 47.17323
## 45 0 1 0 1 0.906 0.453 46.78335
## 46 0 0 0 1 0.872 0.325 46.41172
## 47 0 0 1 0 0.465 0.767 46.29660
## 48 0 0 0 0 0.011 0.511 46.11650
## 49 0 1 0 1 0.267 0.116 45.99583
## 50 0 0 0 1 0.174 0.011 45.73675
## 51 0 0 0 0 0.220 0.116 45.46628
## 52 0 0 0 1 0.313 0.313 44.37552
## 53 0 0 0 1 0.127 0.034 43.08892
## 54 0 0 0 0 0.313 0.511 43.06890
## 55 0 1 0 1 0.872 0.279 42.84914
## 56 0 0 0 1 0.732 0.511 42.27208
## 57 0 0 0 1 0.465 0.465 42.17877
## 58 0 1 0 0 0.186 0.267 41.90431
## 59 0 0 0 0 0.220 0.116 41.38956
## 60 0 1 0 1 0.604 0.837 41.26551
## 61 0 1 0 0 0.732 0.034 39.46056
## 62 0 0 0 1 0.220 0.325 39.44680
## 63 0 1 0 0 0.732 0.325 39.18550
## 64 0 1 0 0 0.046 0.104 39.14106
## 65 0 1 0 0 0.093 0.116 39.01190
## 66 0 0 1 0 0.604 0.511 38.97504
## 67 0 0 0 1 0.906 0.325 38.01096
## 68 0 0 0 1 0.267 0.976 37.88719
## 69 0 0 0 1 0.093 0.023 37.72234
## 70 0 0 0 1 0.581 0.116 37.34852
## 71 0 0 0 1 0.732 0.511 36.01763
## 72 0 1 0 0 0.732 0.965 35.29076
## 73 0 0 0 1 0.220 0.081 34.72200
## 74 0 1 0 1 0.569 0.058 34.57899
## 75 0 0 0 0 0.604 0.325 34.51768
## 76 0 0 0 1 0.465 0.465 34.15896
## 77 0 0 0 1 0.965 0.767 33.43755
## 78 0 0 0 0 0.011 0.116 32.26109
## 79 0 0 0 0 0.418 0.325 32.23100
## 80 0 1 0 1 0.732 0.069 29.70369
## 81 0 1 0 1 0.093 0.511 28.12744
## 82 0 0 0 0 0.162 0.116 27.30386
## 83 0 0 0 1 0.046 0.325 24.52499
## 84 0 0 0 1 0.313 0.511 23.41782
## 85 0 0 0 1 0.197 0.976 22.44534
Conclusion
From the data table, it’s pretty obvious that Reese’s Peanut Butter Cup is the top-ranked candy as it has 84.18% Winprecent. I tried to make a bar graph or a line graph, but all I could come up with was a scatter plot as there are too many candies that are being compared. In the graphs, it is difficult to find out which point is for which candy so there is no clear picture because it’s hard to tell the different types of candy apart. I was really hoping to find a link between the winning candy and things like sugar content or price, but it looks like there’s no strong connection there when looking at the table. I thought about making graphs for the Top 20 Winpercent Candies, but I’m not exactly sure about the code for that.