Overview

The Ultimate Halloween Candy Power Ranking (https://fivethirtyeight.com/videos/the-ultimate-halloween-candy-power-ranking/) by Walt Hickey is an analysis about the most popular Halloween candies. Data was collected by creating a website (http://walthickey.com/2017/10/18/whats-the-best-halloween-candy/), where participants were shown presenting two fun-sized candies and asked to click on the one they would prefer to receive. In total, more than 269 thousand votes were collected from 8,371 different IP addresses. For our purposes, we will be focusing on the sugar content of top ten popular candies.

Load Libraries.

library(tidyverse)
## ── Attaching packages ─────────────────────────────────────── tidyverse 1.3.2 ──
## ✔ ggplot2 3.4.0      ✔ purrr   1.0.1 
## ✔ tibble  3.1.8      ✔ dplyr   1.0.10
## ✔ tidyr   1.3.0      ✔ stringr 1.5.0 
## ✔ readr   2.1.3      ✔ forcats 0.5.2 
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag()    masks stats::lag()

Import file as CSV.

In this code we are uploading the data set from github account.

Candy <- read.csv("https://raw.githubusercontent.com/FarhanaAkther23/DATA607/main/Assignment%201/candy-data.csv") 

We are exploring our data in the following steps:

dim(Candy)
## [1] 85 13

There are 85 different candies and 13 different variables resulted from data dimension

head(Candy, 15)
##                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
##    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

Head brought first 15 rows from data set.

tail(Candy, 15)
##                competitorname chocolate fruity caramel peanutyalmondy nougat
## 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
## 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

Tail brought last 15 rows from data set.

Rename column headers

Candy2 <- rename(Candy,c("CandyName"="competitorname", "Sugarpercent"="sugarpercent", "Popularity"="winpercent"))

in the code above we changed the name of the column

Select a Subset

How many candies have popularity over 70%?

pop_70<-subset(Candy2, Popularity > 70, select=c(CandyName,Sugarpercent,Popularity))
pop_70
##                      CandyName Sugarpercent Popularity
## 29                     Kit Kat        0.313   76.76860
## 33         Peanut butter M&M's        0.825   71.46505
## 37                   Milky Way        0.604   73.09956
## 43         Nestle Butterfinger        0.604   70.73564
## 52          Reese's Miniatures        0.034   81.86626
## 53   Reese's Peanut Butter cup        0.720   84.18029
## 54              Reese's pieces        0.406   73.43499
## 55 Reese's stuffed with pieces        0.988   72.88790
## 65                    Snickers        0.546   76.67378
## 80                        Twix        0.546   81.64291

In the code above, we created a subset pop_70 and we can see there are 10 different candies with popularity over 70%.

Bar Plots

Conclusion

Based on the analyses and visualizations, we can see that although Reese’s Miniatures are one of the most popular top 10 fun size cadies, it contains 0.95 percent sugar than Reese’s stuffed with pieces. Therefore, the preliminary results suggest that Reese’s Miniatures can be a preferable choice for those who want to control their sugar intake.