This is a Self Quantified Project aided at assessing my daily wellness, subjects studied here include: daily food, sleeping hour, activities by hour, coffee use habit, steps and walking distance.
Data collection: Data was collection both manually and digitally. Some variables, such as Steps,Walking + Running Distance and Phone Use time were collected on my iphone time app, While other variables, such as Coffee Use, Sleeping Hour, Reading, Workout are record manually. I put all data into an csv file which can be easiler read by R.
Goal: The goal of this project is to assess my daily wellness. I chose my rest, my food consumption, my activities to represent wellness here. Based on the data I collected, 5 questions are asked for this analysis.
What is the pattern of my walking distance and steps during a week?
What is my coffee consumption habit?
What is my sleeping pattern?
Does the coffee use related to my sleeping time?
How is my time distributed a day? Is it healthy?
Preprocesssing: Data preprocessing is a must for every analysis since no dataset is clean and perfect. The data preperation here includes: making sure of the data type of each variable is correct, rename the variables for ease, convert the variales using minutes as unit to using hr as unit, replacing missing value with the mean of that variable’s value. The dataset below is the cleaned dataset.
Analysis Method: Visulization Analysis is to be used for this project. Packages used here include: ggplot2, ggthemes, plotly, dygraphs, xts, latticeExtra.
| Date | Milk(cup) | Coffee | Sleeping | Watching_TV | Reading | Phone_Use | Steps | Walking_and_Running | Workout | phone_hr | reading_hr |
|---|---|---|---|---|---|---|---|---|---|---|---|
| 2022-09-28 | 2 | 2 | 8.0 | 0.0 | 60 | 230 | 9162 | 4.6 | 2 | 3.8333333 | 1.00 |
| 2022-09-29 | 1 | 0 | 7.0 | 0.0 | 45 | 179 | 9713 | 4.9 | 2 | 2.9833333 | 0.75 |
| 2022-09-30 | 2 | 2 | 5.5 | 2.0 | 60 | 224 | 4987 | 3.5 | 1 | 3.7333333 | 1.00 |
| 2022-10-01 | 2 | 0 | 8.0 | 2.0 | 0 | 166 | 6693 | 3.3 | 2 | 2.7666667 | 0.00 |
| 2022-10-02 | 0 | 1 | 7.0 | 1.0 | 0 | 236 | 4043 | 2.5 | 1 | 3.9333333 | 0.00 |
| 2022-10-03 | 2 | 1 | 8.0 | 0.0 | 0 | 171 | 7495 | 4.2 | 0 | 2.8500000 | 0.00 |
| 2022-10-04 | 1 | 0 | 6.0 | 0.0 | 30 | 122 | 8116 | 4.1 | 0 | 2.0333333 | 0.50 |
| 2022-10-05 | 0 | 0 | 7.0 | 0.5 | 0 | 228 | 4720 | 3.4 | 1 | 3.8000000 | 0.00 |
| 2022-10-06 | 1 | 0 | 6.5 | 0.5 | 45 | 211 | 8725 | 4.9 | 1 | 3.5166667 | 0.75 |
| 2022-10-07 | 2 | 0 | 7.0 | 1.0 | 45 | 34 | 4808 | 2.9 | 1 | 0.5666667 | 0.75 |
| 2022-10-08 | 2 | 0 | 7.0 | 1.0 | 0 | 204 | 8489 | 4.2 | 0 | 3.4000000 | 0.00 |
| 2022-10-09 | 1 | 0 | 7.0 | 1.0 | 0 | 10 | 1020 | 0.5 | 1 | 0.1666667 | 0.00 |
| 2022-10-10 | 2 | 1 | 8.0 | 2.0 | 60 | 140 | 8140 | 5.1 | 1 | 2.3333333 | 1.00 |
| 2022-10-11 | 2 | 1 | 8.0 | 3.0 | 15 | 155 | 2437 | 2.2 | 1 | 2.5833333 | 0.25 |
| 2022-10-12 | 2 | 0 | 8.0 | 2.0 | 15 | 229 | 4226 | 2.6 | 1 | 3.8166667 | 0.25 |
| 2022-10-13 | 2 | 0 | 6.0 | 2.0 | 45 | 71 | 8438 | 4.7 | 0 | 1.1833333 | 0.75 |
| 2022-10-14 | 2 | 2 | 7.0 | 1.0 | 30 | 185 | 6457 | 3.7 | 0 | 3.0833333 | 0.50 |
| 2022-10-15 | 0 | 2 | 8.0 | 2.0 | 60 | 108 | 3265 | 2.1 | 2 | 1.8000000 | 1.00 |
| 2022-10-16 | 2 | 2 | 7.0 | 3.0 | 30 | 196 | 2515 | 2.3 | 1 | 3.2666667 | 0.50 |
| 2022-10-17 | 0 | 2 | 7.0 | 1.5 | 0 | 151 | 4319 | 2.2 | 0 | 2.5166667 | 0.00 |
| 2022-10-18 | 1 | 0 | 7.0 | 2.0 | 15 | 224 | 7411 | 3.7 | 2 | 3.7333333 | 0.25 |
| 2022-10-19 | 1 | 1 | 6.0 | 1.0 | 30 | 49 | 6122 | 4.1 | 1 | 0.8166667 | 0.50 |
| 2022-10-20 | 2 | 0 | 7.0 | 1.0 | 30 | 128 | 2776 | 2.4 | 1 | 2.1333333 | 0.50 |
| 2022-10-21 | 2 | 1 | 8.0 | 2.0 | 45 | 128 | 1962 | 1.5 | 0 | 2.1333333 | 0.75 |
| 2022-10-22 | 0 | 1 | 7.0 | 0.0 | 15 | 150 | 4068 | 3.0 | 1 | 2.5000000 | 0.25 |
| 2022-10-23 | 1 | 0 | 7.0 | 0.0 | 15 | 232 | 3871 | 1.9 | 0 | 3.8666667 | 0.25 |
| 2022-10-24 | 1 | 0 | 6.5 | 0.0 | 0 | 201 | 8205 | 4.1 | 1 | 3.3500000 | 0.00 |
| 2022-10-25 | 1 | 2 | 7.0 | 0.0 | 30 | 149 | 7889 | 4.9 | 0 | 2.4833333 | 0.50 |
| 2022-10-26 | 2 | 0 | 8.0 | 0.0 | 0 | 239 | 2192 | 1.1 | 2 | 3.9833333 | 0.00 |
| 2022-10-27 | 1 | 2 | 8.0 | 0.0 | 45 | 230 | 4569 | 2.3 | 0 | 3.8333333 | 0.75 |
| 2022-10-28 | 2 | 0 | 6.0 | 0.0 | 0 | 238 | 1669 | 1.8 | 1 | 3.9666667 | 0.00 |
| 2022-10-29 | 0 | 1 | 7.0 | 3.0 | 30 | 84 | 8888 | 5.4 | 1 | 1.4000000 | 0.50 |
| 2022-10-30 | 0 | 2 | 7.5 | 2.0 | 0 | 126 | 4403 | 2.2 | 2 | 2.1000000 | 0.00 |
In order to see how much steps I take and the distance of my movement per day, I created two line plot using xyplot function and conbime them into one plot with two y-axis. doubleYScale function is used here since Steps and Walking and Running have different units and y axis. I am also interested in seeing how my movement changes on different weekdays, so boxplot is applied here.
From the plots above we could see:
Steps and Walking and Running Distances are closely related and show the same pattern.
No clear evidence indicate whether I am walking more or less overtime in the past 30 days.
Thursday is my most active day, with highest average steps and walking distance, while I tend to move less on Sunday.
integer(0)
This part introduce my coffe habbit. Firstly I created a piechart and see how often I drink 0,1 and 2 cup of coffee. Then I want to how much coffee I drink overtime, ggplot, geom_point, and geom_jitter is used here. Boxplot is used here again to see whether my coffee use changes on different weekday.
Here’re some insights:
Around 55% of the days I drink one more cup of coffer per day.
Friday, Saturday, Sunday I drink more coffee.
I drink less coffee between Oct 3rd to Oct 10th, and increase the coffee usage after Oct 10th.
I drink coffee less in weekday mostly due to the busy work and no time to cook the coffee.
I like to try different coffee when I travel outside for a coffee shop.
integer(0)
Piechart is firstly used here to see the Sleeping Hour distribution within 30 days. In order to see whether weekday has an effect on my sleeping hour, ggplot and geom_point graphs colored by Weekday variable, as well as a boxplot are used.
More than 75% of the days I had an over 7 hours sleeping. I have 25% days slept less then 6.5 hours
No significant change of sleeping hour in the past 30 days.
I have a very least sleep, 5.5 hours, in Friday due to social acitvity.
I have more sleep time for Monday and Saturday.
Excessive use of coffee might cause sleeping difficulty. I want to see if coffee use influences my sleeping hour. Ggplot and geom_point as well as geom_smooth are used here to see the relationship between my coffee use and sleeping. I also use doubleYScale function to create a plot with 2 y-axis so I could see the pattern of coffee use and sleeping hour at the same time.
From the graphs above:
My Sleeping hour and Coffee Use have a non-linear relationship, and no clear pattern.
I tend to drink more coffee when I have an 7.5 to 8 hr sleep, while I tend to drink less after a 6.5 hr or more sleeping.
I want to see how I spent my day in the last month, therefore dygraph is applied here. I created a new variable called “Other” to represent the rest of time on a day excluding those on the dataset. A stackGraph is used to show the time spent per day and how it changes.
From the graph we could see that:
There are six activities taken into account in this analysis, Sleeping, Watching TV, Phone Use, Workout, Reading, Others.
I spent least time on reading and workout in general, while spent most time on others times.
Suprisingly, I spent more around 2 hours on my phone everyday, which is a huge amount of time.
TV watching is another problem, which takes up around 1 hr per day.
Time use on all activities is pretty stable in the past 33 days, which indicate this has been my lifestyle.
At the beginning of this project I metioned there’re 5 research questions. Let’s look at the answer here:
The Quantified Self revealed my lifestyle and wellness performance, it demonstrated my daily activities, food and time management.Generally speaking, I have no strong or clear time managment pattern to build up myself, such as allocate more time to read and workout. Also, sleep is important to the health, however, 25% of my sleep time are less than 6.5 hours. Besides, I spent 3-4 hours a day on the phone, which indicate more time i have wasted. To keep developing myself, there are some things learned form this project:
be more strict to time management, 1-2 hour reading, 1-2 hour workout.
less time on entertainment, such as watching TV and play phone.
Allocate more time on sleep, make it as a stable pattern.
keep tracking my daily activities and time to improve my lifestyle.
---
title: "Quantified Self Project"
author: "Gefei Yang"
date: "`r Sys.Date()`"
output:
flexdashboard::flex_dashboard:
orientation: rows
vertical_layout: fill
social: menu
source: embed
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE)
#load library
library(readxl)
library(tidyverse)
library(ggplot2)
library(ggthemes)
library(plotly)
library(readxl)
library(dygraphs)
library(xts)
library(latticeExtra)
#import the dataset
self = read_csv("ANLY512_data_final_project.csv")
#take a look at the dataset and see their data types
glimpse(self)
##Pre-processing
# convert the some variable into another data type
self$Date = as.Date(self$Date)
self$`total_phone_use(mins)` = as.numeric(self$`total_phone_use(mins)`)
self$`Sleeping (hrs)`= as.numeric(self$`Sleeping (hrs)`)
glimpse(self)
#change the name of the variables
self = rename(self,Phone_Use=`total_phone_use(mins)`)
self = rename(self,Coffee=`Coffee(cup)`)
self = rename(self, Sleeping = `Sleeping (hrs)`)
self = rename(self, Watching_TV = `Watching TV (hrs)`)
self = rename(self, Reading = `Reading (mins)`)
self = rename(self, Walking_and_Running = `walking + running distance(mile)`)
self = rename(self, Workout = `Gym (hrs)`)
#Convert phone_use and reading variables into hrs
self = self %>% mutate(phone_hr = Phone_Use/60,reading_hr = Reading/60)
#Replace the missing value with the mean of each variable
self$Sleeping[is.na(self$Sleeping)]=mean(self$Sleeping, na.rm = TRUE)
self$Watching_TV[is.na(self$Watching_TV)]=mean(self$Watching_TV, na.rm = TRUE)
self$phone_hr[is.na(self$phone_hr)]=mean(self$phone_hr, na.rm = TRUE)
self$reading_hr[is.na(self$reading_hr)]=mean(self$reading_hr, na.rm = TRUE)
#Add a weekday variable to the dataset
self1 <- self
self1$weekday = weekdays(self1$Date)
self = self1
```
Introduction
=====================================
Row
-----------------------------------------------------------------------
### Summary
- This is a Self Quantified Project aided at assessing my daily wellness, subjects studied here include:
daily food, sleeping hour, activities by hour, coffee use habit, steps and walking distance.
- Data collection: Data was collection both manually and digitally. Some variables, such as Steps,Walking + Running
Distance and Phone Use time were collected on my iphone time app, While other variables, such as Coffee Use, Sleeping
Hour, Reading, Workout are record manually. I put all data into an csv file which can be easiler read by R.
- Goal: The goal of this project is to assess my daily wellness. I chose my rest, my food consumption, my activities to represent
wellness here. Based on the data I collected, 5 questions are asked for this analysis.
1. What is the pattern of my walking distance and steps during a week?
2. What is my coffee consumption habit?
3. What is my sleeping pattern?
4. Does the coffee use related to my sleeping time?
5. How is my time distributed a day? Is it healthy?
- Preprocesssing: Data preprocessing is a must for every analysis since no dataset is clean and perfect. The data preperation here includes: making sure of the data type of each variable is correct, rename the variables for ease, convert the variales using minutes as unit to using hr as unit, replacing missing value with the mean of that variable's value. The dataset below is the cleaned
dataset.
- Analysis Method: Visulization Analysis is to be used for this project. Packages used here include: ggplot2, ggthemes, plotly, dygraphs, xts, latticeExtra.
Row
-----------------------------------------------------------------------
### Dataset with selected variables
```{r}
knitr::kable(self[,c(1,2,4,5,6,7, 8,9,10,11,13,14)])
```
ACTIVITY
=====================================
Row
-------------------------------------
### Steps and Walking + Running Distance by Date
```{r}
#Steps and distance by date
steps = xyplot(Steps ~ Date, self, type = "l" , lwd=2)
distance = xyplot(Walking_and_Running ~ Date, self, type = "l" , lwd=2)
doubleYScale(steps, distance, text = c("Steps", "Distance(miles)") , add.ylab2 = TRUE)
```
### Steps in Weekday
```{r}
#Steps by weekdays
ggplot(self) + geom_boxplot(aes(weekday, Steps)) +
ggtitle('Steps in weekday') + labs(x = "Weekdays") +
theme_classic()
```
### Walking and Running Distance in Weekday
```{r}
#Walking and running distance by weekday
ggplot(self) + geom_boxplot(aes(weekday, Walking_and_Running)) +
ggtitle("Walking and Running Distance in Weekday") + labs(x = "Weekdays", y = "Walking and Running Distance") +
theme_classic()
```
Row {data-height=200}
-------------------------------------
### **Summary**
In order to see how much steps I take and the distance of my movement per day, I created two line plot using xyplot function and conbime them into one plot with two y-axis. doubleYScale function is used here since Steps and Walking and Running have different units and y axis. I am also interested in seeing how my movement changes on different weekdays, so boxplot is applied here.
From the plots above we could see:
- Steps and Walking and Running Distances are closely related and show the same pattern.
- No clear evidence indicate whether I am walking more or less overtime in the past 30 days.
- Thursday is my most active day, with highest average steps and walking distance, while I tend to move less on Sunday.
COFFEE USE
=====================================
Row
-------------------------------------
### Coffee Use Distribution
```{r}
pie(table(self$Coffee)) + title("Coffee Use Distribution")
```
### Coffee use by Date
```{r}
ggplot(self,aes(Date, Coffee)) + geom_point(col = "brown") +
geom_jitter(col = "brown") +
geom_smooth(col = 'red', fill = "pink" ) +
labs(title= "Coffee use by Date") +
theme_classic()
```
### Coffee Use by Weekday
```{r}
ggplot(self) + geom_boxplot(aes(weekday, Coffee)) +
ggtitle("Coffee Use by Weekday") +
labs(y = "Coffee (Cup)") +
theme_classic()
```
Row {data-height=200}
-------------------------------------
### **Summary**
This part introduce my coffe habbit. Firstly I created a piechart and see how often I drink 0,1 and 2 cup of coffee. Then I want to how much coffee I drink overtime, ggplot, geom_point, and geom_jitter is used here. Boxplot is used here again to see whether my coffee use changes on different weekday.
Here're some insights:
- Around 55% of the days I drink one more cup of coffer per day.
- Friday, Saturday, Sunday I drink more coffee.
- I drink less coffee between Oct 3rd to Oct 10th, and increase the coffee usage after Oct 10th.
- I drink coffee less in weekday mostly due to the busy work and no time to cook the coffee.
- I like to try different coffee when I travel outside for a coffee shop.
SLEEPING
=====================================
Row
-------------------------------------
### Sleeping Hour Distribution
```{r}
pie(table(self$Sleeping)) + title('Sleeping Hour Distribution')
```
### Sleeping Hour Per Day
```{r}
ggplot(self) + geom_point(aes(Date, Sleeping, color = weekday))+
theme_classic() +
labs(title = "Sleeping Hour Per Day", y = "Sleeping Hour")
```
### Sleeping Hour Per Weekday
```{r}
ggplot(self) + geom_boxplot(aes(weekday, Sleeping))+
theme_classic() +
labs(title = "Sleeping Hour Per Weekday", y = "Sleeping Hour")
```
Row {data-height=200}
------------------------------------------
### **Summary**
Piechart is firstly used here to see the Sleeping Hour distribution within 30 days. In order to see whether weekday has an effect on my sleeping hour, ggplot and geom_point graphs colored by Weekday variable, as well as a boxplot are used.
- More than 75% of the days I had an over 7 hours sleeping. I have 25% days slept less then 6.5 hours
- No significant change of sleeping hour in the past 30 days.
- I have a very least sleep, 5.5 hours, in Friday due to social acitvity.
- I have more sleep time for Monday and Saturday.
SLEEPING VS COFFEE
=====================================
Row
-------------------------------------
### Sleeping Hour vs Coffee Use
```{r}
ggplotly(ggplot(self,aes(x = Sleeping, y = Coffee))+ geom_point(col = 'brown') + geom_smooth(col = 'red', fill = "pink") +
geom_jitter(col = "brown") +
theme_classic() +
ggtitle("Sleeping Hour vs Coffee Use") +
labs(x = "Sleeping Hours", y = "Coffee Use (Cup)"))
```
### Coffee Use vs Sleeping Hour
```{r}
coffee = xyplot(Coffee ~ Date, self, type = "l" , lwd=2)
sleeping = xyplot(Sleeping ~ Date, self, type = "l" , lwd=2)
doubleYScale(coffee, sleeping, text = c("Coffee Use", "Sleeping Hour") , add.ylab2 = TRUE)
```
Row {data-height=200}
------------------------------------------
### **Summary**
Excessive use of coffee might cause sleeping difficulty. I want to see if coffee use influences my sleeping hour.
Ggplot and geom_point as well as geom_smooth are used here to see the relationship between my coffee use and sleeping. I also use doubleYScale function to create a plot with 2 y-axis so I could see the pattern of coffee use and sleeping hour at the same time.
From the graphs above:
- My Sleeping hour and Coffee Use have a non-linear relationship, and no clear pattern.
- I tend to drink more coffee when I have an 7.5 to 8 hr sleep, while I tend to drink less after a 6.5 hr or more sleeping.
TIME USE
=====================================
Row
-------------------------------------
### Time Use Per Day
```{r}
timeuse = self %>% mutate(other = 24 -Sleeping-Watching_TV-phone_hr-reading_hr-Workout )
timeuse = xts(timeuse[,c(5,6,13,11,14,16)], order.by = timeuse$Date)
dygraph(timeuse,main = "Time Use By Date") %>% dyAxis("y", label = "Hour") %>% dyOptions(stackedGraph = TRUE)
```
Row {data-height=200}
------------------------------------------
### **Summary**
I want to see how I spent my day in the last month, therefore dygraph is applied here. I created a new variable called "Other" to represent the rest of time on a day excluding those on the dataset. A stackGraph is used to show the time spent per day and how it changes.
From the graph we could see that:
- There are six activities taken into account in this analysis, Sleeping, Watching TV, Phone Use, Workout, Reading, Others.
- I spent least time on reading and workout in general, while spent most time on others times.
- Suprisingly, I spent more around 2 hours on my phone everyday, which is a huge amount of time.
- TV watching is another problem, which takes up around 1 hr per day.
- Time use on all activities is pretty stable in the past 33 days, which indicate this has been my lifestyle.
Conclusion
=====================================
Row
------------------------------
### Conclusion
At the beginning of this project I metioned there're 5 research questions. Let's look at the answer here:
1. What is the pattern of my walking distance and steps during a week?
- Thursday is when I walk most and take most steps since I need to walk to metro and office, while Friday I work from home, Sunday I need to take rest for coming workdays.
2. What is my coffee consumption habit?
- I am not addicted to coffee, 50% days I don't drink coffee, but I do drink coffee when I hangout with friends because I cannot digest alcohol.
3. What is my sleeping pattern?
- Most of the days I sleep more than 7 hours. I tend to sleep more on Saturday and Monday, while sleep less on Friday.
4. Does the coffee use related to my sleeping time?
- There is no significant relationship between my coffee use and sleeping hour.
5. How is my time distributed a day? Is it healthy?
- My time spent on each ativities is pretty stable overtime. Other activities, such as working and house work, take up most of the time, while reading and working out take up least of the time.
Row
------------------------------
### **Takeaway**
The Quantified Self revealed my lifestyle and wellness performance, it demonstrated my daily activities, food and time management.Generally speaking, I have no strong or clear time managment pattern to build up myself, such as allocate more time to read and workout. Also, sleep is important to the health, however, 25% of my sleep time are less than 6.5 hours. Besides, I spent 3-4 hours a day on the phone, which indicate more time i have wasted.
To keep developing myself, there are some things learned form this project:
1. be more strict to time management, 1-2 hour reading, 1-2 hour workout.
2. less time on entertainment, such as watching TV and play phone.
3. Allocate more time on sleep, make it as a stable pattern.
4. keep tracking my daily activities and time to improve my lifestyle.