Introduction & Data

Row

Sample of Final Project Data
Date Day Walk.Distance N.of.Meetings Lunch Country Week Seq
2018-06-17 Sunday 3.53 0 Ramen Japanese Week1 1
2018-06-18 Monday 3.24 1 Ribs American Week1 2
2018-06-19 Tuesday 4.91 2 Burrito Mexican Week1 3
2018-06-20 Wednesday 2.84 0 Panini Italian Week1 4
2018-06-21 Thursday 2.10 1 Panini Italian Week1 5
2018-06-22 Friday 3.38 1 Pada Chinese Week1 6
2018-06-23 Saturday 6.78 0 Pho Vietnam Week1 7
2018-06-24 Sunday 2.30 0 BBQ Korean Week2 1
2018-06-25 Monday 4.06 2 Burrito Mexican Week2 2
2018-06-26 Tuesday 2.87 2 Panini Italian Week2 3
2018-06-27 Wednesday 0.90 0 Chicken Jamaican Week2 4
2018-06-28 Thursday 5.60 4 Pierogi Polish Week2 5
2018-06-29 Friday 3.58 0 Ribs American Week2 6
2018-06-30 Saturday 0.99 0 Dumpling Chinese Week2 7
2018-07-01 Sunday 1.85 0 Dumpling Chinese Week3 1
2018-07-02 Monday 4.05 3 Burrito Mexican Week3 2
2018-07-03 Tuesday 4.67 2 Panini Italian Week3 3
2018-07-04 Wednesday 2.20 0 Burger American Week3 4
2018-07-05 Thursday 3.00 0 Burrito Mexican Week3 5
2018-07-06 Friday 3.22 0 Pierogi Polish Week3 6
2018-07-07 Saturday 7.00 0 BBQ Korean Week3 7
2018-07-08 Sunday 1.78 0 Ramen Japanese Week4 1
2018-07-09 Monday 4.22 1 Panini Italian Week4 2
2018-07-10 Tuesday 4.88 3 Pizza Italian Week4 3
2018-07-11 Wednesday 2.10 2 Burrito Mexican Week4 4
2018-07-12 Thursday 2.55 0 Pasta Italian Week4 5
2018-07-13 Friday 3.00 1 Salad American Week4 6
2018-07-14 Saturday 5.28 0 Bread Chinese Week4 7
2018-07-15 Sunday 7.92 0 Noodles Chinese Week5 1
2018-07-16 Monday 4.01 1 Panini Italian Week5 2
2018-07-17 Tuesday 4.82 3 Burrito Mexican Week5 3
2018-07-18 Wednesday 2.69 1 Salad American Week5 4
2018-07-19 Thursday 1.50 0 Burger American Week5 5
2018-07-20 Friday 1.53 2 Pizza Italian Week5 6
2018-07-21 Saturday 6.61 0 Salad American Week5 7
2018-07-22 Sunday 4.52 0 Noodles Chinese Week6 1
2018-07-23 Monday 2.41 1 Panini Italian Week6 2
2018-07-24 Tuesday 5.00 3 Chicken Jamaican Week6 3
2018-07-25 Wednesday 2.20 0 Burrito Mexican Week6 4
2018-07-26 Thursday 2.10 1 Sushi Japanese Week6 5
2018-07-27 Friday 3.45 2 Panini Italian Week6 6
2018-07-28 Saturday 6.00 0 Sushi Japanese Week6 7
2018-07-29 Sunday 1.20 0 BBQ Korean Week7 1
2018-07-30 Monday 4.22 1 Fish American Week7 2
2018-07-31 Tuesday 4.48 2 Fish American Week7 3
2018-08-01 Wednesday 2.23 1 Chicken Jamaican Week7 4
2018-08-02 Thursday 0.67 0 Burrito Mexican Week7 5
2018-08-03 Friday 7.91 4 Panini Italian Week7 6
2018-08-04 Saturday 6.10 0 Pho Vietnam Week7 7
2018-08-05 Sunday 1.20 0 Porridge Chinese Week8 1
2018-08-06 Monday 4.21 1 Panda Chinese Week8 2
2018-08-07 Tuesday 4.32 2 Burrito Mexican Week8 3
2018-08-08 Wednesday 4.06 1 Soup American Week8 4
2018-08-09 Thursday 2.87 1 Panini Italian Week8 5
2018-08-10 Friday 2.96 1 Panini Italian Week8 6
2018-08-11 Saturday 6.20 0 Dumpling Chinese Week8 7

Q1: My Walk Distance Pattern

Row

Daily Walk Distance from June - Aug

Q2: Walk Distance Pattern for Weeday

Row

Daily Walk Distance by Day of the Week (Heat Map)

Q3: N of Meetings vs Walk Distance

Row

Relationship between Walk Distance and Number of Meetings I attend on Weekday

Q4: Lunch

Row

Lunch I have everyday

Q5: Cousin

Row

Cousin type for my lunch

---
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")

```