A project for ANLY512: Data Visualization
The Quantified Self movement grew from the popularity and growth of the internet of things, the mass collection of personal information, and mobile technologies (primarily wearable computing). This final class project uses a collection of seven months of data on sleep habits and physical activity captured by an activity tracker. In particular, I used a Fitbit Charge 2 which tracks a wide variety of data points related to body, food intake, physical activity, and sleep.
The goal of the project is to collect, analyze and visualize the data using the tools and methods covered in class. Additionally, using the data-driven approach, I will create a summary which answers the following questions based on the data collected 1) how much sleep am I getting 2) how does an abundance or lack of sleep affect my activity level 3) when am I the most active 4) how do ‘Number of Awakenings’ effect my sleep 5)
| Date | Calories.Burned | Steps | Distance | Floors | Minutes.Sedentary | Minutes.Lightly.Active | Minutes.Fairly.Active | Minutes.Very.Active | Activity.Calories | Minutes.Asleep | Minutes.Awake | Number.of.Awakenings | Time.in.Bed | total_act | Weekday | Month |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1/1/17 | 3,429 | 12,219 | 5.36 | 16 | 527 | 350 | 48 | 27 | 2,104 | 6.800000 | 30 | 2 | 438 | 425 | 1 | 1 |
| 1/2/17 | 2,237 | 4,407 | 1.93 | 10 | 697 | 138 | 7 | 4 | 625 | 9.200000 | 31 | 4 | 592 | 149 | 2 | 1 |
| 1/3/17 | 2,256 | 5,434 | 2.38 | 13 | 864 | 174 | 0 | 0 | 706 | 7.083333 | 20 | 1 | 448 | 174 | 3 | 1 |
| 1/4/17 | 2,707 | 8,908 | 3.91 | 13 | 764 | 248 | 14 | 9 | 1,192 | 6.333333 | 31 | 2 | 411 | 271 | 4 | 1 |
| 1/5/17 | 2,314 | 5,259 | 2.31 | 18 | 860 | 194 | 0 | 0 | 792 | 6.166667 | 16 | 1 | 386 | 194 | 5 | 1 |
| 1/6/17 | 2,799 | 10,043 | 4.41 | 11 | 715 | 288 | 12 | 22 | 1,415 | 6.450000 | 9 | 2 | 403 | 322 | 6 | 1 |
| 1/7/17 | 2,663 | 10,315 | 4.53 | 6 | 640 | 312 | 6 | 1 | 1,294 | 7.316667 | 42 | 3 | 481 | 319 | 7 | 1 |
| 1/8/17 | 2,500 | 8,404 | 3.69 | 11 | 725 | 231 | 6 | 2 | 1,002 | 7.600000 | 20 | 0 | 476 | 239 | 1 | 1 |
| 1/9/17 | 2,863 | 9,626 | 4.22 | 17 | 731 | 275 | 16 | 23 | 1,371 | 6.066667 | 31 | 3 | 395 | 314 | 2 | 1 |
| 1/10/17 | 2,654 | 8,454 | 3.71 | 17 | 756 | 292 | 0 | 0 | 1,230 | 6.100000 | 26 | 2 | 392 | 292 | 3 | 1 |
| 1/11/17 | 2,484 | 7,575 | 3.32 | 7 | 700 | 279 | 0 | 0 | 1,072 | 7.416667 | 15 | 1 | 461 | 279 | 4 | 1 |
| 1/12/17 | 2,449 | 6,531 | 2.87 | 14 | 868 | 220 | 4 | 4 | 895 | 5.383333 | 20 | 2 | 344 | 228 | 5 | 1 |
| 1/13/17 | 2,489 | 8,251 | 3.62 | 11 | 771 | 241 | 0 | 0 | 1,006 | 6.650000 | 25 | 1 | 424 | 241 | 6 | 1 |
| 1/14/17 | 2,054 | 3,286 | 1.44 | 10 | 648 | 126 | 0 | 0 | 474 | 8.600000 | 31 | 3 | 547 | 126 | 7 | 1 |
| 1/15/17 | 2,051 | 2,876 | 1.26 | 4 | 840 | 94 | 7 | 1 | 427 | 10.116667 | 13 | 1 | 621 | 102 | 1 | 1 |
| 1/16/17 | 2,367 | 4,818 | 2.11 | 10 | 769 | 207 | 0 | 0 | 808 | 6.816667 | 22 | 2 | 431 | 207 | 2 | 1 |
| 1/17/17 | 2,496 | 7,390 | 3.24 | 11 | 717 | 255 | 0 | 0 | 991 | 7.466667 | 23 | 1 | 471 | 255 | 3 | 1 |
| 1/18/17 | 2,599 | 7,796 | 3.42 | 11 | 767 | 296 | 4 | 3 | 1,144 | 6.116667 | 31 | 4 | 400 | 303 | 4 | 1 |
| 1/19/17 | 2,386 | 5,723 | 2.51 | 9 | 855 | 223 | 0 | 0 | 854 | 5.316667 | 9 | 1 | 329 | 223 | 5 | 1 |
| 1/20/17 | 2,506 | 7,464 | 3.27 | 20 | 697 | 256 | 0 | 0 | 1,017 | 7.766667 | 26 | 2 | 492 | 256 | 6 | 1 |
| 1/21/17 | 2,075 | 3,526 | 1.55 | 5 | 848 | 142 | 0 | 0 | 528 | 7.666667 | 18 | 1 | 478 | 142 | 7 | 1 |
| 1/22/17 | 2,342 | 4,296 | 1.88 | 7 | 782 | 127 | 3 | 9 | 717 | 8.150000 | 24 | 2 | 519 | 139 | 1 | 1 |
| 1/23/17 | 2,576 | 7,761 | 3.40 | 15 | 800 | 264 | 0 | 0 | 1,084 | 5.433333 | 18 | 2 | 344 | 264 | 2 | 1 |
| 1/24/17 | 2,445 | 6,694 | 2.94 | 14 | 755 | 240 | 0 | 0 | 931 | 7.600000 | 21 | 2 | 477 | 240 | 3 | 1 |
| 1/25/17 | 2,775 | 9,417 | 4.13 | 17 | 702 | 288 | 7 | 14 | 1,308 | 6.850000 | 15 | 0 | 429 | 309 | 4 | 1 |
https://github.com/rstudio/d3heatmap/
Highlight rows/columns by clicking axis labels
Click and drag over colormap to zoom in (click on colormap to zoom out)
Optional clustering and dendrograms, courtesy of base::heatmap
https://rstudio.github.io/dygraphs/
Automatically plots xts time series objects (or any object convertible to xts).
Highly configurable axis and series display (including optional second Y-axis).
Rich interactive features including zoom/pan and series/point highlighting.
Various graph overlays including shaded regions, event lines, and point annotations.
If you use ggplot2, ggplotly() converts your plots to an interactive, web-based version! It also provides sensible tooltips, which assists decoding of values encoded as visual properties in the plot.
plotly supports some chart types that ggplot2 doesn’t (such as 3D surface, point, and line plots). You can create these (or any other plotly) charts using plot_ly().
https://hrbrmstr.github.io/metricsgraphics/
Building metricsgraphics charts follows the “piping” idiom made popular through the magrittr, ggvis and dplyr packages. This makes it possible to avoid one giant function with a ton of parameters and facilitates breaking out the chart building into logical steps.
While MetricsGraphics.js charts may not have the flexibility of ggplot2
https://hrbrmstr.github.io/metricsgraphics/
Building metricsgraphics charts follows the “piping” idiom made popular through the magrittr, ggvis and dplyr packages. This makes it possible to avoid one giant function with a ton of parameters and facilitates breaking out the chart building into logical steps.
While MetricsGraphics.js charts may not have the flexibility of ggplot2
https://hrbrmstr.github.io/metricsgraphics/
Building metricsgraphics charts follows the “piping” idiom made popular through the magrittr, ggvis and dplyr packages. This makes it possible to avoid one giant function with a ton of parameters and facilitates breaking out the chart building into logical steps.
While MetricsGraphics.js charts may not have the flexibility of ggplot2
https://hrbrmstr.github.io/metricsgraphics/
Building metricsgraphics charts follows the “piping” idiom made popular through the magrittr, ggvis and dplyr packages. This makes it possible to avoid one giant function with a ton of parameters and facilitates breaking out the chart building into logical steps.
While MetricsGraphics.js charts may not have the flexibility of ggplot2
---
title: "HTML Widgets Showcase"
output:
flexdashboard::flex_dashboard:
storyboard: true
social: menu
source: embed
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE)
library(flexdashboard)
library(knitr)
library(ggplot2)
library(tidyverse)
library(readxl)
library(dplyr)
library(xts)
library(zoo)
library(lubridate)
fit <- read.csv("~/Documents/CourseWork/Grad Program/Summer 2017/Final Assignment/fitbit_dataset.csv")
fit_rev <- subset(fit, fit$Time.in.Bed > 0)
## combine activity values into a summary column
fit_rev$total_act <- fit_rev[,7]+fit_rev[,8]+fit_rev[,9]
## convert minutes to hours
fit_rev$Minutes.Asleep <- fit_rev[,11]/60
## create day of week day column
fit_rev$Weekday <- wday(parse_date_time(fit_rev[,1], 'mdy'))
## create day of week day column
fit_rev$Month <- month(parse_date_time(fit_rev[,1], 'mdy'))
```
### The Quantified Self assignment overview
```{r}
gauge(42, min = 0, max = 100, symbol = '%', gaugeSectors(
success = c(80, 100), warning = c(40, 79), danger = c(0, 39)
))
```
***
A project for ANLY512: Data Visualization
The Quantified Self movement grew from the popularity and growth of the internet of things, the mass collection of personal information, and mobile technologies (primarily wearable computing). This final class project uses a collection of seven months of data on sleep habits and physical activity captured by an activity tracker. In particular, I used a Fitbit Charge 2 which tracks a wide variety of data points related to body, food intake, physical activity, and sleep.
The goal of the project is to collect, analyze and visualize the data using the tools and methods covered in class. Additionally, using the data-driven approach, I will create a summary which answers the following questions based on the data collected 1) how much sleep am I getting 2) how does an abundance or lack of sleep affect my activity level 3) when am I the most active 4) how do 'Number of Awakenings' effect my sleep 5)
### Data preparation
```{r}
kable(fit_rev[1:25,], caption="Sample raw data")
```
***
https://github.com/rstudio/d3heatmap/
- Highlight rows/columns by clicking axis labels
- Click and drag over colormap to zoom in (click on colormap to zoom out)
- Optional clustering and dendrograms, courtesy of base::heatmap
### Question 1
```{r}
fill <- "gold1"
line <- "goldenrod2"
p1 <- ggplot(fit_rev, aes(x = Weekday, y=Minutes.Asleep)) +
geom_boxplot(aes(group = Weekday), fill = fill, colour = line) +
scale_x_discrete(limits=c("Sun","Mon","Tues","Wed","Thur","Fri","Sat")) +
labs(title = "Hours asleep per week day", x = "Weekdays", y = "Hours") +
theme_minimal()
p1
p2 <- ggplot(fit_rev, aes(x = Month, y=Minutes.Asleep)) +
geom_boxplot(aes(group = Month), fill = fill, colour = line) +
scale_x_discrete(limits=c("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec")) +
labs(title = "Hours asleep per month", x = "Months", y = "Hours") +
theme_minimal()
p2
#fit <- fit[1:196,]
#fit$Weekday <- factor(fit$Weekday, #levels=c("Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"))
#fit_bg <- fit
#p <- ggplot(fit, aes(x=fit$Date, y=fit$hrs.asleep, group=fit$Weekday)) +
# geom_line(mapping=aes(color=fit$Weekday)) + theme_light() +
# theme(axis.ticks = element_blank(), axis.text.x = element_blank()) +
# guides(colour = guide_legend("DOW")) +
# labs(title = "#1 Hours asleep by Day of Week (DOW)",x = "Jan 1 - July 31", y="Hours asleep")
#p
```
***
https://rstudio.github.io/dygraphs/
- Automatically plots xts time series objects (or any object convertible to xts).
- Highly configurable axis and series display (including optional second Y-axis).
- Rich interactive features including zoom/pan and series/point highlighting.
- Display upper/lower bars (e.g. prediction intervals) around series.
- Various graph overlays including shaded regions, event lines, and point annotations.
### Question 2
```{r}
library(plotly)
p <- ggplot(data = diamonds, aes(x = cut, fill = clarity)) +
geom_bar(position = "dodge")
ggplotly(p)
```
***
https://plot.ly/ggplot2/
If you use ggplot2, `ggplotly()` converts your plots to an interactive, web-based version! It also provides sensible tooltips, which assists decoding of values encoded as visual properties in the plot.
plotly supports some chart types that ggplot2 doesn't (such as 3D surface, point, and line plots). You can create these (or any other plotly) charts using `plot_ly()`.
### Question 3
```{r}
library(metricsgraphics)
mjs_plot(mtcars, x=wt, y=mpg) %>%
mjs_point(color_accessor=carb, size_accessor=carb) %>%
mjs_labs(x="Weight of Car", y="Miles per Gallon")
```
***
https://hrbrmstr.github.io/metricsgraphics/
Building metricsgraphics charts follows the “piping” idiom made popular through the magrittr, ggvis and dplyr packages. This makes it possible to avoid one giant function with a ton of parameters and facilitates breaking out the chart building into logical steps.
While MetricsGraphics.js charts may not have the flexibility of ggplot2
### Question 4
```{r}
library(metricsgraphics)
mjs_plot(mtcars, x=wt, y=mpg) %>%
mjs_point(color_accessor=carb, size_accessor=carb) %>%
mjs_labs(x="Weight of Car", y="Miles per Gallon")
```
***
https://hrbrmstr.github.io/metricsgraphics/
Building metricsgraphics charts follows the “piping” idiom made popular through the magrittr, ggvis and dplyr packages. This makes it possible to avoid one giant function with a ton of parameters and facilitates breaking out the chart building into logical steps.
While MetricsGraphics.js charts may not have the flexibility of ggplot2
### Question 5
```{r}
library(metricsgraphics)
mjs_plot(mtcars, x=wt, y=mpg) %>%
mjs_point(color_accessor=carb, size_accessor=carb) %>%
mjs_labs(x="Weight of Car", y="Miles per Gallon")
```
***
https://hrbrmstr.github.io/metricsgraphics/
Building metricsgraphics charts follows the “piping” idiom made popular through the magrittr, ggvis and dplyr packages. This makes it possible to avoid one giant function with a ton of parameters and facilitates breaking out the chart building into logical steps.
While MetricsGraphics.js charts may not have the flexibility of ggplot2
### Summary
```{r}
library(metricsgraphics)
mjs_plot(mtcars, x=wt, y=mpg) %>%
mjs_point(color_accessor=carb, size_accessor=carb) %>%
mjs_labs(x="Weight of Car", y="Miles per Gallon")
```
***
https://hrbrmstr.github.io/metricsgraphics/
Building metricsgraphics charts follows the “piping” idiom made popular through the magrittr, ggvis and dplyr packages. This makes it possible to avoid one giant function with a ton of parameters and facilitates breaking out the chart building into logical steps.
While MetricsGraphics.js charts may not have the flexibility of ggplot2