Column

Total Minutes Asleep by Day

Total Steps

Column

Steps vs Calories

Total Distance vs Calories

Active Time per Day

Row

Background and Research Questions

Sport band is very popular right now, because people start to care about their life and health. Everyone wants to monitor his own life and try to live healthy. 1. How was my sleep every day? 2. Did I exercise enough? 3. Is there any relationship between steps I walked and calories burned? 4. Is there any relationship between walking distance and calories burned? 5. How many days I did work out?

---
title: "Health Status in 2018"
Author: "Jiaoyuan Huang"
output:
  flexdashboard::flex_dashboard:
    orientation: rows
    social: menu
    source_code: embed
---

```{r setup, include=FALSE}
library(flexdashboard)
```

```{r}
setwd('C:/Users/Emily/Desktop/512')
Data <- read.csv('data_health_data.csv')
```

Column {data-width=500}
-----------------------------------------------------------------------

### Total Minutes Asleep by Day

```{r}
library(ggplot2)
theme_set(theme_bw())

# Plot
ggplot(Data, aes(x=Day, y=TotalMinutesAsleep)) + 
  geom_point(size=3) + 
  geom_segment(aes(x=ActivityDay, 
                   xend=ActivityDay, 
                   y=0, 
                   yend=TotalMinutesAsleep)) + 
  labs(title="Total Minutes Asleep by Day") + 
  theme(axis.text.x = element_text(angle=65, vjust=0.6))
```



### Total Steps

```{r}
library(ggplot2)
theme_set(theme_classic())

# Plot
g <- ggplot(Data, aes(Day, StepTotal))
g + geom_bar(stat="identity", width = 0.5, fill="tomato2") + 
      labs(title="Total Steps") +
      theme(axis.text.x = element_text(angle=65, vjust=0.6))
```

Column {data-width=450}
-----------------------------------------------------------------------

### Steps vs Calories

```{r}
library(ggplot2)
library(scales)
theme_set(theme_classic())

# Plot
ggplot(Data, aes(x=StepTotal, y=Calories)) + 
  geom_point(col="tomato2", size=2) +   # Draw points
  geom_segment(aes(x=StepTotal, 
                   xend=StepTotal, 
                   y=min(Calories), 
                   yend=max(Calories)), 
               linetype="dashed", 
               size=0.01) +   # Draw dashed lines
  labs(title="The relatioinship between Steps vs Calories") +  
  coord_flip()
```


### Total Distance vs Calories
    
```{r}
options(scipen=999)  # turn-off scientific notation like 1e+48
library(ggplot2)
theme_set(theme_bw())  # pre-set the bw theme.
data("Data", package = "ggplot2")


# Scatterplot
gg <- ggplot(Data, aes(x=TotalDistance, y=Calories)) + 
  geom_point(aes(col=TotalMinutesAsleep, size=StepTotal)) + 
  labs(y="Calories", 
       x="TotalDistance", 
       title="The Relationship Between Exercise Distance and Calories")

plot(gg)
```
    
### Active Time per Day

```{r}
library(ggplot2)

df <- as.data.frame(table(Data$ActivityDay))
colnames(df) <- c("ActivityDay", "VeryActiveMinutes")
pie <- ggplot(df, aes(x = "", y=VeryActiveMinutes, fill = factor(ActivityDay))) + 
  geom_bar(width = 1, stat = "identity") +
  theme(axis.line = element_blank(), 
        plot.title = element_text(hjust=0.5)) + 
  labs(fill="ActivityDay", 
       x=NULL, 
       y=NULL, 
       title="Number of Workout Days vs Number of No Workout Days")

pie + coord_polar(theta = "y", start=0)
```

Row
-----------------------------------------------------------------------

#####Background and Research Questions  
Sport band is very popular right now, because people start to care about their life and health. Everyone wants to monitor his own life and try to live healthy.
1.	How was my sleep every day?
2.	Did I exercise enough?
3.	Is there any relationship between steps I walked and calories burned?
4.	Is there any relationship between walking distance and calories burned?
5.	How many days I did work out?