library(readxl)
## Warning: package 'readxl' was built under R version 3.5.3
DB_DataVizProject_Food <- read_excel("C:/Users/Priya/Downloads/DB-DataVizProject-All.xlsx", 
    sheet = "Food")
DB_DataVizProject_WK <- read_excel("C:/Users/Priya/Downloads/DB-DataVizProject-All.xlsx", 
    sheet = "Workout")
DB_DataVizProject_WKdate <- read_excel("C:/Users/Priya/Downloads/DB-DataVizProject-All.xlsx", 
    sheet = "Sheet1")
Aman <- DB_DataVizProject_Food[450:872,]
Aman_wk <- DB_DataVizProject_WK[43:63,]
AmanWk1 <- Aman[1:141,]
AmanWk2 <- Aman[142:282,]
AmanWk3 <- Aman[283:423,]
Aman_wkdate <- DB_DataVizProject_WKdate[43:63,]
library(ggplot2)
## Warning: package 'ggplot2' was built under R version 3.5.3
Aman$date <- Aman$`Date (mm/dd/yyyy)`
AmanWk1$Date <- AmanWk1$`Date (mm/dd/yyyy)`
AmanWk2$Date <- AmanWk2$`Date (mm/dd/yyyy)`
AmanWk3$Date <- AmanWk3$`Date (mm/dd/yyyy)`

library(tidyr)
library(dplyr)
## Warning: package 'dplyr' was built under R version 3.5.2
## 
## 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(ggmap)
## Warning: package 'ggmap' was built under R version 3.5.3
## Google's Terms of Service: https://cloud.google.com/maps-platform/terms/.
## Please cite ggmap if you use it! See citation("ggmap") for details.
Aman$Carbs <- Aman$`Carbs(g)`
Aman$Fat <- Aman$`Fat(g)`
Aman$Proteins <- Aman$`Proteins(g)`
Aman_n <- Aman[,c(7,10)]
Aman_s <- Aman[,c(8,10)]

Aman$`Day of the Week` <- as.character(Aman$`Day of the Week`)

Aman$`Day of the Week` <- factor(Aman$`Day of the Week`, levels=unique(Aman$`Day of the Week`))

Aman$`Day of the Week` <- factor(Aman$`Day of the Week`, levels=c("Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"))

# QUESTION 01 

# What distribution of calorific value during every week based on Different Food Type. 

ggplot(AmanWk1, aes(x = Date, y = Calories)) + 
  geom_col(aes(color = `Food Type`, fill = `Food Type`))

# As shown in the Week 01 Graph for Aman the Average Calorific Value is 2074. Wednesday and Saturday 
# show the highest Calorific Value during Week 01 and Fruits, Vegan are the top two Food Type          # categories and Caffeinated, Dairy being the least contributor. 

ggplot(AmanWk2, aes(x = Date, y = Calories)) + 
  geom_col(aes(color = `Food Type`, fill = `Food Type`))

# As shown in the Week 02 Graph for Aman the Average Calorific Value is 2074. Wednesday and Saturday   # show the highest Calorific Value during Week 01 and Fruits, Vegan are the top two Food Type          # categories and Caffeinated, Dairy being the least contributor. 

ggplot(AmanWk3, aes(x = Date, y = Calories)) + 
  geom_col(aes(color = `Food Type`, fill = `Food Type`))

# As shown in the Week 02 Graph for Aman the Average Calorific Value is 2074. Wednesday and Saturday   # show the highest Calorific Value during Week 01 and Fruits, Vegan are the top two Food Type          # categories and Caffeinated, Dairy being the least contributor. 

# Conclusion- Aman is 30 Years old male who weighs 95 Kgs is 175 cms tall. He consumed on an average   # over the three-week period 2074 calories. As per the Harris-Benedict Equation for Basal Energy       # Expenditure (BEE), which is Men: BEE = 66.5 + 13.8(W) + 5.0(H) - 6.8(A) and Women: BEE = 655.1 +     # 9.6(W) + 1.9(H) - 4.7(A), Aman’s BEE should be [66.5+ 13.8(95) + 5.0(175) - 6.8(30)]= 2048.5. Also,  # BEE may need to be multiplied by a factor of 1.2-1.5 to account for extra calories needed during     # exercise. A factor of 1.2 represents an average amount of activity, where 1.5 would be a very high   # amount of activity. Since Aman does average amount of activity hence his BEE should be multiplied by # a factor of 1.2. Therefore, his new BEE is 2048.5*1.2 which is 2458.2. Hence, Aman is consuming less # Calories as compared to the BEE number

df_aman <- data.frame(value = c(6930.90, 1787.70, 2463.60),
                 Group = c("Carbs", "Proteins", "Fats")) %>%
   mutate(Group = factor(Group, levels = c("Fats", "Proteins", "Carbs")),
          cumulative = cumsum(value),
          midpoint = cumulative - value / 2,
          label = paste0(Group, " ", round(value / sum(value) * 100, 1), "%"))

# QUESTION 02 

# What is the distribution of the 3 major Nutrients in grams.

ggplot(df_aman, aes(x = 1, weight = value, fill = Group)) +
   geom_bar(width = 1, position = "stack") +
   coord_polar(theta = "y") +
   geom_text(aes(x = 1.3, y = midpoint, label = label)) +
   theme_nothing()  

# The American Dietetic Association (ADA) recommends daily protein intake for healthy adults as       # 0.8-1.0 g of protein/kg body weight, Fat intake should equal 30% of your total day’s calories and   # the USDA recommends that 45 to 65 percent of your total daily calories come from carbohydrates. Also # 1 calorie= 0.1295978 grams. 

# [Source](https://www.k-state.edu/paccats/Contents/Nutrition/PDF/Needs.pdf)

# So as per the data from Aman’s pie-chart and the average calorific count over the three-week period # which was 2074 calories, Aman should be consuming- 

# Protein (grams)- 

# 95kgs * (0.8 g/kg) = 76 grams 

# 95kgs * (1.0 g/kg) =  95 grams 

# As per the data Aman is consuming on an average 85 grams of protein per day which is within his 76  # grams to 95 grams limit. 

# Fat (grams)- 

# 30% * 2074 calories= 737.46 calories 

# In Grams-> 737.46 calories/9 = 81.94 grams 

# As per the data Aman is consuming on an average 117.31 grams of fat per day which is over his 81.94 grams limit. 

# Fat (grams)- 

# 45% * 2074 calories = 933.3 calories 

# In Grams-> 933.3 calories/9 = 103.7 grams 

# 65% * 2074 calories = 1348.1 calories 

# In Grams-> 1348.1calories/9 = 149.79 grams 

# As per the data Aman is consuming on an average 330.04 grams of carbs per day which is over his 103.7 grams to 149.79 grams limit. 

# ggplot(Aman_n, aes(x="", y=Calories, fill=`Food Type`))+

# QUESTION 03 

# What is distribution of eating habits based on Different Food Types. 

ggplot(Aman_n, aes(x="", y=Calories, fill=`Food Type`))+
geom_bar(width = 1, stat = "identity") + 
  coord_polar("y", start=0)

# From the pie-chart we can see that Aman’s major food intake is from Fruits and Vegan food type while Dairy and Lean Meats and Poultry and Caffeinated are the least contributors. 

# QUESTION 04 

# What is distribution of eating habits based on Different Food Sources. 

ggplot(Aman_s, aes(x="", y=Calories, fill=`Food Source`)) +
geom_bar(width = 1, stat = "identity") + 
  coord_polar("y", start=0)

# From the pie-chart we can see that Aman’s major food intake is from Natural/Raw and Packaged Snacks food source while Restaurant and pre-Cooked are the least contributors. 

# QUESTION 05 

# What is distribution of eating habits based on Different Food Sources over different days of the week.

ggplot(Aman, aes(x = `Day of the Week`, y = Calories)) + 
  geom_col(aes(color = `Food Source`, fill = `Food Source`))

# Home Cooked- During Saturday and Sunday Aman eats more Home Cooked food than the rest of the days of the week. 

# Pre-Cooked- Consistent Distribution during the week. 

# Restaurant- Major contributor on Tuesdays and Wednesdays 

# Natural/Raw- Except Sunday and Tuesday it shows Consistent Distribution during the week. 

# Water- Consistent Distribution during the week. 

# Packaged Snacks- Consistent Distribution during the week. 

# QUESTION 06 

# Distribution of Calories Consumed vs Calories burned through Physical Exercises over different days of the week. 

ggplot() + 
  geom_col(data = Aman_wkdate, aes(x = Date, y = Calories), color = "cyan", fill = "white") +
  geom_line(data = Aman_wk, aes(x = `Date (mm/dd/yyyy)`, y = `Calories Burnt`), color = "red") +
  xlab('Date') +
  ylab('Calorie difference')