Column ———————————————————————–
The quantified self refers both to the cultural phenomenon of self-tracking with technology and to a community of users and makers of self-tracking tools who share an interest in “self-knowledge through numbers”.
The goal of the dashboard is to captures the metrics associated with my activity and sleep data and analyse the overall welness of my body with respect to exercise and rest.
It tries to answer the following questions:
What are the overall stats associated with my body?
What are my activity patterns?
What are my calorie burning patterns?
What are my sleep patterns?
The data is sourced from my fitbit by exporting the data from there. It contains data from July 2020 when the device was firt purchases. There are some missing data which is when I don’t wear the device.
Activity Data includes following data:
Date,Calories Burned, Steps, Distance, Floors, Minutes,Sedentary Minutes, Lightly Active, Minutes Fairly Active, Minutes Very Active, Activity Calories
Sleep Data includes the following data:
Start Time,End Time,Minutes Asleep,Minutes Awake, Number of Awakenings,Time in Bed,Minutes REM Sleep, Minutes Light Sleep, Minutes Deep Sleep
### Day Activity Difference
The Fitbit data is not available for a number of days.
For the days it is available, average number of steps is around 3000 which indicates a sedentary lifestyle.
Sundays are my most active day.
Calories burnt has a direct correlation with number of steps or activity
Quantity and corrrespondigly, quality of sleep depends on the number of times one awakes during the night.
---
title: "Quantified Self"
subtitle: "A project for ANLY 512: Data Visualization"
author: "Anushmita Roy Choudhury"
date: "`r Sys.Date()`"
output:
flexdashboard::flex_dashboard:
orientation: rows
social: menu
source_code: embed
---
```{r setup, include=FALSE, message=FALSE}
# list of libraries we are using in this dashboard
library(flexdashboard)
library(quantmod)
library(plyr)
library(dygraphs)
library(lubridate)
library(RColorBrewer)
library(DT)
library(tidyverse)
library(scales)
library(ggthemes)
library(ggplot2)
library(gridExtra)
#Data Fetching
ActivityData= read.csv("Activities.csv",TRUE, sep = ",", stringsAsFactors = FALSE)
SleepData= read.csv("Sleep.csv",TRUE, sep = ",", stringsAsFactors =TRUE)
#CleanData
summary(ActivityData)
summary(SleepData)
ActivityData$Date=as.Date(ActivityData$Date)
#summary(ActivityData)
#summary(SleepData)
SleepData$TypeofSleep=ifelse(is.na(SleepData$Minutes.REM.Sleep), "Nap", "Normal Sleep")
SleepData[is.na(SleepData)] = 0
library(anytime)
SleepData$Start.Time=anytime(as.factor(SleepData$End.Time), tz="EST")
SleepData$End.Time=anytime(as.factor(SleepData$End.Time),tz="EST")
#summary(SleepData)
seasons = c(
"01" = "Winter", "02" = "Winter",
"03" = "Spring", "04" = "Spring", "05" = "Spring",
"06" = "Summer", "07" = "Summer", "08" = "Summer",
"09" = "Fall", "10" = "Fall", "11" = "Fall",
"12" = "Winter"
)
ActivityData$Season=seasons[format(ActivityData$Date, "%m")]
SleepData$Season=seasons[format(SleepData$Start.Time, "%m")]
ActivityData$Day = weekdays(as.Date(ActivityData$Date),abbreviate=TRUE)
SleepData$Day = weekdays(as.Date(SleepData$Start.Time),abbreviate=TRUE)
```
# Project Overview
###
Column
-----------------------------------------------------------------------
###

Column
-----------------------------------------------------------------------
###
The quantified self refers both to the cultural phenomenon of self-tracking with technology and to a community of users and makers of self-tracking tools who share an interest in "self-knowledge through numbers".
The goal of the dashboard is to captures the metrics associated with my activity and sleep data and analyse the overall welness of my body with respect to exercise and rest.
It tries to answer the following questions:
1. What are the overall stats associated with my body?
2. What are my activity patterns?
3. What are my calorie burning patterns?
4. What are my sleep patterns?
The data is sourced from my fitbit by exporting the data from there. It contains data from July 2020 when the device was firt purchases. There are some missing data which is when I don't wear the device.
Activity Data includes following data:
Date,Calories Burned, Steps, Distance, Floors, Minutes,Sedentary Minutes, Lightly Active, Minutes Fairly Active, Minutes Very Active, Activity Calories
Sleep Data includes the following data:
Start Time,End Time,Minutes Asleep,Minutes Awake, Number of Awakenings,Time in Bed,Minutes REM Sleep, Minutes Light Sleep, Minutes Deep Sleep
# Step Counts
Column {.tabset}
-----------------------------------------------------------------------
### Step Count
```{r message=FALSE, warning=FALSE}
ggplot(ActivityData, aes(Steps, fill = cut(Steps, 1000))) + geom_histogram(show.legend = FALSE, fill="#778ba5", colour="#012345") +
labs(x = "Step Count") +
ggtitle("Step Count Distribution")+theme_classic()
```
### Weekly Step Count Heat Map
```{r message=FALSE, warning=FALSE}
ggplot(data=ActivityData,aes(x=Day, y=Season, fill=Steps)) +
geom_tile(col = 'lightblue') +
theme(panel.grid.major = element_blank()) +
labs(title = "Weekly Step Count Heatmap") +
guides(fill=FALSE)+
coord_equal()+scale_fill_gradient(name ="Steps",
low = "#FFFFFF",
high ="#012345")+theme_classic()
```
### Day Activity Difference
```{r message=FALSE, warning=FALSE}
ActivityData$DayType = sapply(ActivityData$Date, function(x) {
if(weekdays(x) == "Saturday" | weekdays(x) == "Snday")
{y <- "Weekend"}
else {y <- "Weekday"}
y
})
ggplot(ActivityData, aes(x = Date , y = Steps, color = DayType)) +
geom_line(color="#778ba5") + ggtitle("Average Weekly Steps by Day Type") +
xlab("Date") +
ylab("Average Number of Steps") +
facet_wrap(~DayType, ncol = 1, nrow=2) +
scale_color_discrete(name = "Day Type") +theme_classic()
```
# Calories
Column {.tabset}
-----------------------------------------------------------------------
### Calories and Steps
```{r message=FALSE, warning=FALSE}
p1=ggplot(ActivityData, aes(x = Steps, y = Calories.Burned))+
geom_point() +
stat_smooth(method = "lm",
col = "#2a52be",
se = FALSE,
size = 1) + xlab("Steps") + ylab("Calories Burned") +geom_point(color = "#778ba5")+theme_classic()
coeff =20
p2=ggplot(ActivityData,aes(x = Date)) +
geom_line(aes(y = Calories.Burned), color = "light blue")+geom_line( aes(y = Steps/coeff, color="red", linetype = "twodash")) + scale_y_continuous(name = "Calories",sec.axis = sec_axis(~.*coeff, name = "Steps"))+ xlab("")+
labs(title ="Calories and Steps over Time")+theme_classic()
grid.arrange(p1,p2)
```
### Calories and Lifestyle
```{r message=FALSE, warning=FALSE}
library(ggplot2)
library(gridExtra)
very_active=ggplot(ActivityData, aes(Calories.Burned, Minutes.Very.Active)) +
geom_point(color="#002e63")+ geom_smooth(method = 'loess') + labs(title="Calories when Very Active", x= "Calorie Expenditure", y= "Very Active Minutes")+theme_classic()
fairly_active=ggplot(ActivityData, aes(Calories.Burned, Minutes.Fairly.Active)) +
geom_point(color="#0047ab")+ geom_smooth(method = 'loess') + labs(title="Calories when Moderately Active", x= "Calorie Expenditure", y= "Fairly Active Minutes")+theme_classic()
lightly_active=ggplot(ActivityData, aes(Calories.Burned, Minutes.Lightly.Active )) +
geom_point( color="#4682b4")+ geom_smooth(method = 'loess') + labs(title="Calories when Little Active", x= "Calorie Expenditure", y= "Lightly Active Minutes")+theme_classic()
sedentary=ggplot(ActivityData, aes(Calories.Burned, Minutes.Sedentary)) +
geom_point(color="#87ceeb")+ geom_smooth(method = 'loess') + labs(title="Calories when Sedentary", x= "Calorie Expenditure", y= "Sedentary Minutes")+theme_classic()
grid.arrange(very_active, fairly_active, lightly_active, sedentary,nrow=2,ncol=2)
```
# Sleep Patterns
Column {.tabset}
-----------------------------------------------------------------------
### Sleep HeatMap
```{r, message=FALSE, warning=FALSE, results='hide'}
ggplot(data=SleepData,aes(x=Day, y=Season, fill=Minutes.Asleep)) +
geom_tile(col = 'lightblue') +
theme(panel.grid.major = element_blank()) +
labs(title = "Weekly Step Count Heatmap") +
guides(fill=FALSE)+
coord_polar()+scale_fill_gradient(name = "Minutes.Asleep",
low = "#FFFFFF",
high = "#012345")+theme_classic()
```
### Sleep Restlessness
```{r, message=FALSE, warning=FALSE, results='hide'}
NormalSleepData=subset(SleepData, Number.of.Awakenings<20)
ggplot(NormalSleepData, aes(Number.of.Awakenings, Minutes.Asleep, fill=Minutes.Asleep)) + geom_col(position="dodge") +
labs(title = "Awakenings vs Sleep Time", x = "Awakenings per night", y = "Hours asleep (stacked)", show.legend = FALSE)+theme_classic()
```
# Conclusion
Column
-----------------------------------------------------------------------
### Observations from the visualisations
1. The Fitbit data is not available for a number of days.
2. For the days it is available, average number of steps is around 3000 which indicates a sedentary lifestyle.
3. Sundays are my most active day.
4. Calories burnt has a direct correlation with number of steps or activity
5. Quantity and corrrespondigly, quality of sleep depends on the number of times one awakes during the night.