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")
Prashant <- DB_DataVizProject_Food[155:449,]
PrashantWk1 <- Prashant[1:115,]
PrashantWk2 <- Prashant[116:207,]
PrashantWk3 <- Prashant[208:295,]
library(ggplot2)
## Warning: package 'ggplot2' was built under R version 3.5.3
Prashant$Date <- Prashant$`Date (mm/dd/yyyy)`
PrashantWk1$Date <- PrashantWk1$`Date (mm/dd/yyyy)`
PrashantWk2$Date <- PrashantWk2$`Date (mm/dd/yyyy)`
PrashantWk3$Date <- PrashantWk3$`Date (mm/dd/yyyy)`
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(tidyr)
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.
Prashant$Carbs <- Prashant$`Carbs(g)`
Prashant$Fat <- Prashant$`Fat(g)`
Prashant$Proteins <- Prashant$`Proteins(g)`
Prashant_n <- Prashant[,c(7,10)]
Prashant_s <- Prashant[,c(8,10)]

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

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

Prashant$`Day of the Week` <- factor(Prashant$`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(PrashantWk1, aes(x = Date, y = Calories)) + 
  geom_col(aes(color = `Food Type`, fill = `Food Type`))

#As shown in the Week 01 Graph for Prashant the Average Calorific Value is 2510. Wednesday and Thursday show the highest Calorific Value during Week 01 and Fruits, Dairy are the top two Food Type categories and Snacks being the least contributor. 

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

#As shown in the Week 02 Graph for Prashant the Average Calorific Value is 3007. Monday show the highest Calorific Value during Week 02 and Grain, Dairy are the top two Food Type categories and Snacks being the least contributor. 

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

#As shown in the Week 03 Graph for Prashant the Average Calorific Value is 2628. Sunday and Monday show the highest Calorific Value during Week 03 and Grain, Dairy are the top two Food Type categories and Snacks being the least contributor. 

#Conclusion- Prashant is 30 Years old male who weighs 65 Kgs is 177 cms tall. He consumed on an average over the three-week period 2715 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), Prashant’s BEE should be [66.5+ 13.8(65) + 5.0(177) - 6.8(30)] = 1644.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 Prashant does average amount of activity hence his BEE should be multiplied by a factor of 1.2. Therefore, his new BEE is 1644.5*1.2 which is 1973.4. Hence, Prashant is consuming high Calories as compared to the BEE number. 

df_prashant <- data.frame(value = c(5031.15, 2067.31, 1177.99),
                 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_prashant, 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 Prashant’s pie-chart and the average calorific count over the three-week period which was 2715 calories, Prashant should be consuming- 

#Protein (grams)- 

#65kgs * (0.8 g/kg) = 52 grams 

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

#As per the data Prashant is consuming on an average 38 grams of protein per day which is less his 52 grams to 65 grams limit. 

#Fat (grams)- 

#30% * 2715 calories= 814.5 calories 

#In Grams-> 814.5 calories/9 = 90.5 grams 

#As per the data Prashant is consuming on an average 58.9 grams of fat per day which is less his 90.5 grams limit. 

#Fat (grams)- 

#45% * 2715 calories = 1221.75 calories 

#In Grams-> 1221.75 calories/9 = 135.75 grams 

#65% * 2715 calories = 1764.75 calories 

#In Grams-> 1764.75 calories/9 = 196.08 grams 

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

## QUESTION 03 

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

ggplot(Prashant_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 Prashant’s major food intake is from Grain and Dairy food type while Snacks and caffeinated are the least contributors. 

# QUESTION 04 

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

ggplot(Prashant_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 Prashant’s major food intake is from Home Cooked and Natural/Raw food source while Food Truck/Street Food and Restaurant are the least contributors. 

# QUESTION 05 

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

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

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

#Food Truck/Street Food – It shows only Thursday. 

#Restaurant- Major contributor on Friday 

#Natural/Raw- During Monday and Wednesday it shows Consistent Distribution during the week. 

#Packaged Snacks- Consistent Distribution during the week.