---
title: "ANLY 512 Final Project -- Ling Shen"
output:
flexdashboard::flex_dashboard:
orientation: rows
vertical_layout: fill
source_code: embed
---
```{r setup, include=FALSE}
library(flexdashboard)
library(readxl)
library(scales)
library(wesanderson)
library(ggplot2)
library(RColorBrewer)
library(plyr)
library(ggmap)
library(fiftystater)
library(knitr)
Project_Data <- read_excel("D:/HU/2018 Summer/ANLY512/Fianl Project/Project Data.xlsx")
location <- read_excel("D:/HU/2018 Summer/ANLY512/Fianl Project/Location.xlsx")
Project_Data$Date <- as.Date(Project_Data$Date)
summary(Project_Data)
str(Project_Data)
```
Introduction & Data
============================
Intro {.sidebar}
------------------------------------------
Introduction
* The Quantified Self(QS) can be explained as know yourslef through numbers and it is a very good method to know more about ourselves. In this final project, I collected the data about distance I walked and food I eat for my lunch and try to answer some interesting questions I developed.
Data I collected
* I collected a series of data about myself and I think the data I collected is very meaningful. The date range of my data is from June 17th to August 11st. I use fitbit to collect my distance data;record number of meetings I had based on my working calendar; write down what I eat everyday after my lunch.
* There are eight variables in my dataset. Date indicates the specific day. Day is day of the week. Walk.Distance shows how long is the walk distance for that specific day. N.of.Meetings means number of meetings I have for every day. Lunch indicates the food I eat every day. Country is the cousin related to my lunch. Week represents which week. Seq is from 1-7, 1 means Sunday, 2 stands for Monday,and 7 means Saturday.
Row
--------------------------------------------------------------
```{r}
kable(Project_Data, caption = "Sample of Final Project Data")
```
Q1: My Walk Distance Pattern
============================
Intro {.sidebar}
------------------------------------------
Q1: What's my walk distance everyday? Is there any pattern?
* From June 17th to August 11st this year, my highest walk distance is 8KM, the lowest walk distance is 0.2 and the average walk distance is round 4 KM. I live 6 miles far away from my company and everyday I drive to work. Honestly speaking, most of the walking activity happened when I at my company.
* From the line graph on the right, we can find that there does exist a pattern for my walk distance from June 17th to August 11st. It seems like every week I will have a peak for my walk distance.
Row {data-height=400}
--------------------------------------------------------------
###Daily Walk Distance from June - Aug
```{r}
#1. Daily Walk Distance from June - Aug (Line Graph)
ggplot(Project_Data,aes(x=Date,y=Walk.Distance))+
geom_line(color = 'coral', size = 1.5)+
xlab("Date") + ylab("Walk Distance (KM)")+
theme(legend.position = "bottom", plot.title = element_text(hjust=0.5))+
ggtitle("Daily Walk Distance from June 17th 2018 to August 11th 2018")
```
Q2: Walk Distance Pattern for Weeday
=====================================
Intro {.sidebar}
------------------------------------------
Q2: What's the walk distance pattern for each day winthin one week?
* Since the pattern does exist for my walk distance in the last figure. I would like to use a heat map to analyze the pattern and figure out whether I walk more on specific days than others winthin a week.
* According to the heat map on the right, on average, I walk the most on Saturdays. I think the reason is because I shop a lot on Saturdays. For weekdays, obvisously, I walk more on Monday and Tuesday than Wednesday, Thursday and Friday. I think the reson is because I usually have a lot of work needs to do from Wednesday to Fridays, thus, needs to stay at my cube.
Row
--------------------------------------------------------------
###Daily Walk Distance by Day of the Week (Heat Map)
```{r}
#2. Daily Walk Distance by Day of the Week (Heat Map & Order )
ggplot(data=Project_Data,aes(x = reorder(Day,Seq),y = Week)) +
geom_tile(aes(fill = Walk.Distance), colour = "white") +
ggtitle("Daily Walk Distance Pattern from June 17th 2018 to August 11th 2018") +
scale_x_discrete("Day of the Week", labels = c("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday")) +
theme(plot.title = element_text(hjust=0.5)) +
scale_fill_gradient(" Walk\nDistance", low = "white", high = "indianred1")
```
Q3: N of Meetings vs Walk Distance
==================================
Intro {.sidebar}
------------------------------------------
Q3: Will Number of Meetings I attend in each weekday affect my walk distance?
* Form the graph on the right, we can see that the more number of meetings I have on the weekday, the higher walk distance I will have.
Row
--------------------------------------------------------------
###Relationship between Walk Distance and Number of Meetings I attend on Weekday
```{r}
#1. The relationship between Walk Distance and Number of Meetings on Weekday
# Conclusion: More number of meetings I attend, the higher walk distance I have
Mon.Fri <- subset(Project_Data,Day %in% c("Monday","Tuesday","Wednesday","Thursday","Friday"))
ggplot(data=Mon.Fri, aes(x = N.of.Meetings, y = Walk.Distance)) +
geom_point(aes(colour = factor(Day)),size = 3) +
geom_smooth(method = 'lm') +
theme(panel.border = element_blank(),plot.title = element_text(hjust=0.5)) +
xlab("Number of Meetings") + ylab("Walk Distance") +
ggtitle("The relationship between Number of Meetings and Walk Distance on Weekdays \n June 17th 2018 - August 11th 2018")
```
Q4: Lunch
==========
Intro {.sidebar}
------------------------------------------
Q4: What food do I eat for my luch? What kind of food I eat most?
* According to the bar chart on the right, for lunch, I eat Panini and Burrito a lot. We have a fooda station at the first floor of our company, and I usually order Panini and Burrito since these 2 I think is healty for me. In adddition, my lunch is very diverse, I eat a lot of differnt food.
Row
--------------------------------------------------------------
###Lunch I have everyday
```{r,fig.width=10.5,fig.height=6}
#1. Lunch I have Everyday
Lunch <- count(Project_Data,'Lunch')
ggplot(Lunch,aes(x = reorder(Lunch,-freq),y = freq))+
geom_bar(stat="identity",colour= "darkseagreen", fill = "darkseagreen3")+
xlab("Food") + ylab("Count") +
theme(legend.position = "bottom", plot.title = element_text(hjust=0.5)) +
ggtitle("Lunch Category June 17th 2018 - August 11th 2018") +
scale_y_continuous(name = "Count", limits=c(0,12)) +
theme_bw() +
geom_text(aes(label = freq), vjust = -0.25, size = 4)
```
Q5: Cousin
=======================================================
Intro {.sidebar}
------------------------------------------
Q5: How about the cousin category for my lunch?
* In general, from June 17th to August 11st, I eat Italian cousin the most, almost 25% of my lunch is Italian cousin. In addition, I eat american food, chinese food, and mexican food a lot as well. My lunch is very diverse, I've been tried all kinds of cousin over the world.
Row
--------------------------------------------------------------
###Cousin type for my lunch
```{r}
#2. Cousin Type
#brewer.pal(11,"Spectral")#Get the color code of Spectral color palette
Cousin <- count(Project_Data,'Country')
Cousin.update <- Cousin[order(-Cousin$freq),]
pct <- round(Cousin.update$freq/sum(Cousin$freq)*100)
lbls <- paste(Cousin.update$Country, pct)
lbls <- paste(lbls,"%",sep="")
pie(Cousin.update$freq,labels = lbls,col=c("#D53E4F","#F46D43","#FDAE61","#FEE08B","#FFFFBF","#ABDDA4","#66C2A5","#3288BD","#5E4FA2"), main = "Cousin for my Lunch")
```