The data set provides comprehensive nutritional information, including calorie counts, macro nutrient contents, and micro nutrients, from six prominent fast-food restaurant chains: McDonald’s, Burger King, Wendy’s, Kentucky Fried Chicken (KFC), Taco Bell, and Pizza Hut. It encompasses various attributes such as Calories, Calories from Fat, Total Fat, Saturated Fat, Trans Fat, Cholesterol, Sodium, Carbs, Fiber, Sugars, Protein, and Weight Watchers Points (where available).
Although, there is various attributes to choose from I focused on the nutrients that are included in Calories, Total Fat, Cholesterol, Sodium and Carbs. The visualizations included in this assignment displays information about these nutrients and how they interact with each other.
Here is the link to the dataset: https://www.kaggle.com/datasets/joebeachcapital/fast-food?select=FastFoodNutritionMenuV2.csv
The data set consists of 924 observations, each representing a specific fast-food item, with details categorized by ‘Company’ and ‘Item’. The summary statistics reveal a wide range of values across the nutritional attributes. For instance, the calorie content varies from a minimum of 100 to a maximum of 1220, with a mean of approximately 345.8 calories per item. Total fat content ranges from 0 to 98 grams, with an average of 13.48 grams. Similarly, cholesterol content varies from 0 to 575 milligrams, with a mean of 45.83 milligrams. Sodium content ranges from 0 to 2890 milligrams, with an average of 503.9 milligrams, indicating significant variability in the salt content of these items. Carbohydrate content varies from 0 to 270 grams, with an average of 44.38 grams.
suppressWarnings(suppressMessages(library(MVA)))
suppressWarnings(suppressMessages(library(reshape2)))
suppressWarnings(suppressMessages(library(ggplot2)))
suppressWarnings(suppressMessages(library(data.table)))
suppressWarnings(suppressMessages(library(dplyr)))
suppressWarnings(suppressMessages(library(httr)))
suppressWarnings(suppressMessages(library(lubridate)))
fastfood <- fread("FastFoodNutritionMenuV2.csv", na.strings = c(NA,""))
colnames(fastfood) <- gsub("[\n ]", " ", colnames(fastfood))
fastfood <- fastfood %>%
select(Company,Item,Calories,`Total Fat (g)`,`Cholesterol (mg)`,`Sodium (mg)`,`Carbs (g)`)%>%
filter(Calories != 0)%>%
data.frame()
names(fastfood) <- c("Company", "Item", "Calories", "TotalFat(g)", "Cholesterol(mg)", "Sodium(mg)", "Carbs(g)")
#Switching all columns to integers
fastfood$Calories <- as.integer(fastfood$Calories, na.rm = TRUE)
fastfood$`TotalFat(g)` <- as.integer(fastfood$`TotalFat(g)`, na.rm = TRUE)
fastfood$`Cholesterol(mg)` <- as.integer(fastfood$`Cholesterol(mg)`, na.rm = TRUE)
fastfood$`Sodium(mg)`<- as.integer(fastfood$`Sodium(mg)`, na.rm = TRUE)
fastfood$`Carbs(g)` <- as.integer(fastfood$`Carbs(g)`, na.rm = TRUE)
fastfood <- replace(fastfood, is.na(fastfood), 0)
fastfood <- fastfood %>%
filter(Calories >= 100 )%>%
data.frame()
names(fastfood) <- c("Company", "Item", "Calories", "TotalFat(g)", "Cholesterol(mg)", "Sodium(mg)", "Carbs(g)")
summary(fastfood)
## Company Item Calories TotalFat(g)
## Length:924 Length:924 Min. : 100.0 Min. : 0.00
## Class :character Class :character 1st Qu.: 190.0 1st Qu.: 0.00
## Mode :character Mode :character Median : 290.0 Median :10.00
## Mean : 345.8 Mean :13.48
## 3rd Qu.: 430.0 3rd Qu.:20.00
## Max. :1220.0 Max. :98.00
## Cholesterol(mg) Sodium(mg) Carbs(g)
## Min. : 0.00 Min. : 0.0 Min. : 0.00
## 1st Qu.: 0.00 1st Qu.: 95.0 1st Qu.: 26.00
## Median : 25.00 Median : 300.0 Median : 39.00
## Mean : 45.83 Mean : 503.9 Mean : 44.38
## 3rd Qu.: 55.00 3rd Qu.: 810.0 3rd Qu.: 56.00
## Max. :575.00 Max. :2890.0 Max. :270.00
Created new data frame called “average_data” that calculates the average of each nutrient column. With that I created a stacked bar chart that displays which displays that there is high sodium averages in all fast food restaurants.
High levels of sodium consumption is an issue in America especially concerning Fast Food. Therefore I created a chart that displays how much of each company items are above the recommended daily value which is 1250 mg. Burger King and KFC items are extremely high in sodium above recommended value.
## Warning: Using `size` aesthetic for lines was deprecated in ggplot2 3.4.0.
## ℹ Please use `linewidth` instead.
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.
Separated the fast food data frame into smaller ones that only contain each fast food restaurant data. I also created new variables/ columns that calculate the percentage of each item in regards to the recommended daily value of 2000 calories diet.
# McDonald
mcdonalds <- fastfood %>%
select(Company, Calories, `TotalFat(g)`, `Cholesterol(mg)`, `Sodium(mg)`, `Carbs(g)`) %>%
filter(Company == 'Mcdonalds') %>%
filter(Calories != 0)%>%
mutate(dv_calories = (Calories/2000) * 100) %>%
mutate(dv_totalfat = (`TotalFat(g)`/65) * 100) %>%
mutate(dv_cholesterol = (`Cholesterol(mg)`/65) * 100) %>%
mutate(dv_sodium = (`Sodium(mg)`/65) * 100) %>%
mutate(dv_carbs = (`Carbs(g)`/65) * 100) %>%
data.frame()
names(mcdonalds) <- c("Company","Calories", "TotalFat(g)", "Cholesterol(mg)", "Sodium(mg)", "Carbs(g)","Calories DV%","TotalFat DV%","Cholesterol DV%","Sodium DV%","Carbs DV%")
# Burger King
burgerking <- fastfood %>%
select(Company, Calories, `TotalFat(g)`, `Cholesterol(mg)`, `Sodium(mg)`, `Carbs(g)`) %>%
filter(Company == 'Burger King') %>%
filter(Calories != 0)%>%
mutate(dv_calories = (Calories/2000) * 100) %>%
mutate(dv_totalfat = (`TotalFat(g)`/65) * 100) %>%
mutate(dv_cholesterol = (`Cholesterol(mg)`/300) * 100) %>%
mutate(dv_sodium = (`Sodium(mg)`/2400) * 100) %>%
mutate(dv_carbs = (`Carbs(g)`/300) * 100) %>%
data.frame()
names(burgerking) <- c("Company","Calories", "TotalFat(g)", "Cholesterol(mg)", "Sodium(mg)", "Carbs(g)","Calories DV%","TotalFat DV%","Cholesterol DV%","Sodium DV%","Carbs DV%")
# Wendy's
wendys <- fastfood %>%
select(Company, Calories, `TotalFat(g)`, `Cholesterol(mg)`, `Sodium(mg)`, `Carbs(g)`) %>%
filter(Company == 'Wendys') %>%
filter(Calories != 0)%>%
mutate(dv_calories = (Calories/2000) * 100) %>%
mutate(dv_totalfat = (`TotalFat(g)`/65) * 100) %>%
mutate(dv_cholesterol = (`Cholesterol(mg)`/300) * 100) %>%
mutate(dv_sodium = (`Sodium(mg)`/2400) * 100) %>%
mutate(dv_carbs = (`Carbs(g)`/300) * 100) %>%
data.frame()
names(wendys) <- c("Company","Calories", "TotalFat(g)", "Cholesterol(mg)", "Sodium(mg)", "Carbs(g)","Calories DV%","TotalFat DV%","Cholesterol DV%","Sodium DV%","Carbs DV%")
# KFC
kfc <- fastfood %>%
select(Company, Calories, `TotalFat(g)`, `Cholesterol(mg)`, `Sodium(mg)`, `Carbs(g)`) %>%
filter(Company == 'KFC') %>%
filter(Calories != 0)%>%
mutate(dv_calories = (Calories/2000) * 100) %>%
mutate(dv_totalfat = (`TotalFat(g)`/65) * 100) %>%
mutate(dv_cholesterol = (`Cholesterol(mg)`/300) * 100) %>%
mutate(dv_sodium = (`Sodium(mg)`/2400) * 100) %>%
mutate(dv_carbs = (`Carbs(g)`/300) * 100) %>%
data.frame()
names(kfc) <- c("Company","Calories", "TotalFat(g)", "Cholesterol(mg)", "Sodium(mg)", "Carbs(g)","Calories DV%","TotalFat DV%","Cholesterol DV%","Sodium DV%","Carbs DV%")
# Taco Bell
tacobell <- fastfood %>%
select(Company, Calories, `TotalFat(g)`, `Cholesterol(mg)`, `Sodium(mg)`, `Carbs(g)`) %>%
filter(Company == 'Taco Bell') %>%
filter(Calories != 0)%>%
mutate(dv_calories = (Calories/2000) * 100) %>%
mutate(dv_totalfat = (`TotalFat(g)`/65) * 100) %>%
mutate(dv_cholesterol = (`Cholesterol(mg)`/300) * 100) %>%
mutate(dv_sodium = (`Sodium(mg)`/2400) * 100) %>%
mutate(dv_carbs = (`Carbs(g)`/300) * 100) %>%
data.frame()
names(tacobell) <- c("Company","Calories", "TotalFat(g)", "Cholesterol(mg)", "Sodium(mg)", "Carbs(g)","Calories DV%","TotalFat DV%","Cholesterol DV%","Sodium DV%","Carbs DV%")
# Pizza Hut
pizzahut <- fastfood %>%
select(Company, Calories, `TotalFat(g)`, `Cholesterol(mg)`, `Sodium(mg)`, `Carbs(g)`) %>%
filter(Company == 'Pizza Hut') %>%
filter(Calories != 0)%>%
mutate(dv_calories = (Calories/2000) * 100) %>%
mutate(dv_totalfat = (`TotalFat(g)`/65) * 100) %>%
mutate(dv_cholesterol = (`Cholesterol(mg)`/300) * 100) %>%
mutate(dv_sodium = (`Sodium(mg)`/2400) * 100) %>%
mutate(dv_carbs = (`Carbs(g)`/300) * 100) %>%
data.frame()
names(pizzahut) <- c("Company","Calories", "TotalFat(g)", "Cholesterol(mg)", "Sodium(mg)", "Carbs(g)","Calories DV%","TotalFat DV%","Cholesterol DV%","Sodium DV%","Carbs DV%")
McDonald’s is the most consumed fast food company in the world. The goal was to take a look at how the nutrients in their items relate with each other. Each box in the upper half diagonal of the grid displays the scatter plot between the variables. Each box in the lower half diagonal gives the scatter plot with a line of the best fit between the variables. There is not much correlation between the variables.
Taco bell is another staple fast food company in America. Americans tend to take in too much sodium daily. Therefore I used this plot to show that at Taco bell that most of there items are low in sodium percentage levels the calorie percentage level is of that item is still high.
This plot illustrates that Burger King, KFC and McDonald’s items cause items to eat way over the recommended daily value for a 2000 calorie diet.
# Combine all the data frames into one
all_fastfood <- rbind(mcdonalds, burgerking, wendys, kfc, tacobell, pizzahut)
# Melt the data frame for easy plotting
melted_data <- melt(all_fastfood[, c("Company","Calories DV%","Sodium DV%","TotalFat DV%","Cholesterol DV%","Carbs DV%" )], id.vars = "Company")
## Warning: c("The melt generic in data.table has been passed a data.frame and will attempt to redirect to the relevant reshape2 method; please note that reshape2 is superseded and is no longer actively developed, and this redirection is now deprecated. To continue using melt methods from reshape2 while both libraries are attached, e.g. melt.list, you can prepend the namespace, i.e. reshape2::melt(all_fastfood[, c(\"Company\", \"Calories DV%\", \"Sodium DV%\", \"TotalFat DV%\", ). In the next version, this warning will become an error.",
## "The melt generic in data.table has been passed a data.frame and will attempt to redirect to the relevant reshape2 method; please note that reshape2 is superseded and is no longer actively developed, and this redirection is now deprecated. To continue using melt methods from reshape2 while both libraries are attached, e.g. melt.list, you can prepend the namespace, i.e. reshape2::melt( \"Cholesterol DV%\", \"Carbs DV%\")]). In the next version, this warning will become an error.")
# Create the grouped bar chart
trellis_bar_chart <- ggplot(melted_data, aes(x = variable, y = value, fill = Company)) +
geom_bar(stat = "identity", position = "dodge") +
labs(title = "Daily Value Percentage of Key Nutrients for Fast Food Restaurants",
x = "Nutrient", y = "DV%") +
scale_fill_manual(values = c("#FF9999", "#66CCFF", "#FFCC66", "#99FF99", "#FF99FF", "#9999FF")) + # Custom color palette
theme_minimal()+
ylim(0, 100) # Adjusting the y-axis limits
print(trellis_bar_chart)
## Warning: Removed 338 rows containing missing values (`geom_bar()`).