Project Summary

Introduction and Questions

Last September, I started a new job in the state of Idaho and moved from New York to here. Since then, I have been going through an entirely different work experience also a brand-new lifestyle. I was seeking methods of illustration and visualization of this life change and answering some of questions I have been deliberating. Fortunately, I have taken this course this semester and learned some data visualization skills that can be applied on this research. Here are the questions for this project: 1. How different were my daily burned calories after switching to the new job? 2. Was the exercise time affected by the change of job? 3. Did I stand longer in the new job? 4. What was the tendency of my steps tracking in the past 9 months? 5. What was the factor that is mostly correlated to burned calories? E.g. exercise time, stand time or steps

Data Visualization

My apple watch was able to track all my activity data since May 18th, 2019. The data of daily burned calories, exercise time, stand time and steps was exported to R in XML format. There were 269 observations of burned calories, exercise time, stand time and 41,953 observations of steps from the original dataset from May 18th, 2019 to Feb 13th, 2020. All zero values were removed from the dataset because that represents the days when I didn’t wear the watch. The steps data was summarized on a monthly basis in order to manifest the tendency. ggplot was used for data visualization in this project. Three interactive plot charts and one bar chart were created to illustrate the daily tendency of burned calories, exercise time, stand time and monthly tendency of steps. From the four charts as shown on the next page, all activities expect exercise time had an increased tendency after Sep. 2019. Both burned calories and stand time reached peak in November 2019. Both stand time and Steps are positively correlated to burned calories. The tendencies indicated that this new job has elevated my daily stand time and steps which caused more burned caleroies everyday. In addition, this job didn’t affect my exercise time significantly.

Visualization

---
title: "512 Final Project - Yucheng Hu"
output: 
  flexdashboard::flex_dashboard:
    source_code: embed
    orientation: columns
    vertical_layout: fill
---

```{r setup, include=FALSE}
library(flexdashboard)
library(XML)
library(ggplot2)
library(lubridate)
library(dplyr)
library(plotly)

setwd("C:\\Users\\huyc5\\OneDrive\\ANLY 512\\Homework\\export\\apple_health_export")
health <- xmlParse('export.XML')
Record <-   XML:::xmlAttrsToDataFrame(health["//Record"])
Activity1 <- XML:::xmlAttrsToDataFrame(health["//ActivitySummary"])

Activity = subset(Activity1[c(1,2,5,7)])
colnames(Activity) = c('Date','CaloriesBurned','ExerciseTime', 'StandTime')
Activity$Date = as.Date(Activity$Date, '%Y-%m-%d')
Activity$CaloriesBurned = as.numeric(as.character(Activity$CaloriesBurned))
Activity$ExerciseTime = as.numeric(as.character(Activity$ExerciseTime))
Activity$StandTime = as.numeric(as.character(Activity$StandTime))
Activity[Activity==0] <- NA
Activity_clean = na.omit(Activity)

Steps = Record[Record$type == 'HKQuantityTypeIdentifierStepCount',]
Steps$value <- as.numeric(as.character(Steps$value))
Steps$endDate <-ymd_hms(Steps$endDate,tz="America/New_York")
Steps$date<-format(Steps$endDate,"%Y-%m-%d")
Steps$month<-format(Steps$endDate,"%Y-%m")
```
# Project Summary

Introduction and Questions

Last September, I started a new job in the state of Idaho and moved from New York to here. Since then, I have been going through an entirely different work experience also a brand-new lifestyle. I was seeking methods of illustration and visualization of this life change and answering some of questions I have been deliberating. Fortunately, I have taken this course this semester and learned some data visualization skills that can be applied on this research. Here are the questions for this project:
1.	How different were my daily burned calories after switching to the new job? 
2.	Was the exercise time affected by the change of job?
3.	Did I stand longer in the new job?
4.	What was the tendency of my steps tracking in the past 9 months?
5.	What was the factor that is mostly correlated to burned calories? E.g. exercise time, stand time or steps

Data Visualization

My apple watch was able to track all my activity data since May 18th, 2019. The data of daily burned calories, exercise time, stand time and steps was exported to R in XML format. There were 269 observations of burned calories, exercise time, stand time and 41,953 observations of steps from the original dataset from May 18th, 2019 to Feb 13th, 2020. 
All zero values were removed from the dataset because that represents the days when I didn’t wear the watch. The steps data was summarized on a monthly basis in order to manifest the tendency. ggplot was used for data visualization in this project. Three interactive plot charts and one bar chart were created to illustrate the daily tendency of burned calories, exercise time, stand time and monthly tendency of steps.
From the four charts as shown on the next page, all activities expect exercise time had an increased tendency after Sep. 2019. Both burned calories and stand time reached peak in November 2019. Both stand time and Steps are positively correlated to burned calories. The tendencies indicated that this new job has elevated my daily stand time and steps which caused more burned caleroies everyday. In addition, this job didn't affect my exercise time significantly. 


# Visualization

##

### 

```{r}
ggplotly(ggplot(Activity_clean, aes(Date, CaloriesBurned)) + 
           geom_point(alpha = 0.3) + geom_smooth(span = 0.2) +
           labs(y = 'Calories Burned (kcal)', title = 'Calorie Tracker'))
```



### 

```{r}
ggplotly(ggplot(Activity_clean, aes(Date, ExerciseTime)) + 
  geom_point(alpha = 0.3) + geom_smooth(span = 0.2) +
    labs(y = 'Exercise Time (min)', title = 'Exercise Time Tracker'))
```

## 

###

```{r}
ggplotly(ggplot(Activity_clean, aes(Date, StandTime)) + 
  geom_point(alpha = 0.3) + geom_smooth(span = 0.2) +
    labs(y = 'Stand Time (min)'), title = 'Stand Time Tracker') 
```

###
```{r}
Steps %>%
  group_by(month) %>%
  summarize(steps=sum(value)) %>%
  ggplot(aes(x=month, y=steps)) + 
  geom_bar(stat='identity') +
  labs(x = 'Month', y = 'Steps', title = 'Steps Tracker')
```