Overview

Column

Project Write Up

Project Questions

  1. How can I check if my heart rate is normal?
  2. How can I check if my resting heart rate is normal?
  3. Do I have normal active energy calories per day?
  4. How can I check if my average step is normal?
  5. Do I have normal average walking heart rate?

Data Acquisition and Storage

Data for this project was exported from Apple Watch using Health Auto Export application to convert raw data to .csv files. There are many health categories that can be exported from this application such as Activity, Body Measurements, Heart, etc. Also, this application allows us to select range of data by specifying Start Date, End Date, Interval, Export Format, and Sources.

Data Manipulation

There are few data manipulation processes for this project includes modifying date format, reviewing missing data, grouping, and factoring to ensure compatibility to RStudio.

Visualization Methods

This project used multiple RStudio library to visualize data including flexdashboard, tidyverse, ggplot2, dplyr, and reshape2. The figures visualized in this dashboard includes bar chart, line chart, scatter plot, etc.

Question 1

Column

Figure 1

Question 2

Column

Figure 2

Question 3

Column

Figure 3

Question 4

Column

Figure 4

Question 5

Column

Figure 5

---
title: "ANLY 512-91 - Course Project"
author: "Janvich Vanichpipat"
output: 
  flexdashboard::flex_dashboard:
    orientation: columns
    vertical_layout: fill
    source_code: embed
editor_options: 
  chunk_output_type: console
---

```{r setup, include=FALSE}
library(flexdashboard)
library(tidyverse)
library(ggplot2)
library(dplyr)
library(reshape2)
#library(ggiraph)
#library(dygraphs)
#library(xts)
```

Overview
=======================================================================

Inputs {.sidebar}
-----------------------------------------------------------------------

#### <b>Introduction</b>

This course project focuses on tracking and monitoring heart rate and activity data to analyze and check if it is normal or not. The dashboard consists of five project questions mainly on various parameter of heart rate and calories burned per day. The range of the data used in this project starting from November 1, 2022, to November 30, 2022.


Column
-----------------------------------------------------------------------

### Project Write Up

#### <b>Project Questions</b>

1.	How can I check if my heart rate is normal?
2.	How can I check if my resting heart rate is normal?
3.	Do I have normal active energy calories per day?
4.	How can I check if my average step is normal?
5.	Do I have normal average walking heart rate?

#### <b>Data Acquisition and Storage</b>

Data for this project was exported from Apple Watch using Health Auto Export application to convert raw data to .csv files. There are many health categories that can be exported from this application such as Activity, Body Measurements, Heart, etc. Also, this application allows us to select range of data by specifying Start Date, End Date, Interval, Export Format, and Sources.

#### <b>Data Manipulation</b>

There are few data manipulation processes for this project includes modifying date format, reviewing missing data, grouping, and factoring to ensure compatibility to RStudio.

#### <b>Visualization Methods</b>

This project used multiple RStudio library to visualize data including flexdashboard, tidyverse, ggplot2, dplyr, and reshape2. The figures visualized in this dashboard includes bar chart, line chart, scatter plot, etc.


Question 1
=======================================================================

Inputs {.sidebar}
-----------------------------------------------------------------------

#### <b>Question 1</b>

How can I check if my heart rate is normal?

I can check if my heart rate is normal by comparing with the target heart rate zone at my age (30-35). Target heart rate is a range of numbers that reflect how fast your heart should be beating when you exercise. According to Johns Hopkins cardiologist Michael Blaha, M.D., M.P.H., a higher heart rate is a good thing that leads to greater fitness.
Hear rate should be in this zone during exercise.

Figure 1 shows the heart rate data (minimum, maximum, and average) from 11/1/22 to 11/30/22. The ribbon area shows the Target Heart Rate zone for male at age of 30. According to American Heart Association, Target HR Zone 50-85% at age of 30 years is 95-162 bpm. As we can see, most of the maximum heart rate is within the normal target heart rate zone except on 11/11/22 that the value went up to 180 BPM which is unhealthy and too high. 


Column
-----------------------------------------------------------------------

### Figure 1
```{r}
DF <- read.csv("Heart Rate Data1.csv") %>%
  rename(
    Date = Date.Time,
    Min = Min..count.min.,
    Max = Max..count.min.,
    Avg = Avg..count.min.
  )
DF_long <- melt(DF, Date = "Date") 
DF_long$Date <- as.Date(DF_long$Date, format = "%m/%d/%Y")
p1 <- ggplot(DF_long, aes(x = Date, y = value, color = variable)) +
  geom_line() +
  geom_point() +
  geom_ribbon(aes(x = Date,
                  ymin = 95,
                  ymax = 162,
                  fill = "Target Heart Rate Zone (95-162 bpm)"),
              alpha = 0.25,
              color = NA) +
  scale_color_manual(values=c('Coral1','Brown','Brown2')) +
  scale_y_continuous(limits = c(0,200), expand = c(0,0)) +
  labs(
    x = "Date",
    y = "Heart Rate (bpm)",
    title = "Monthly Heart Rate Data - November 2022",
    subtitle = "Data source: Apple Watch",
    color = "Heart Rate Type") +
  theme_light() +
  theme(
    axis.ticks = element_blank(),
    axis.text = element_text(size = 6),
    axis.title = element_text(size = 6),
    plot.title = element_text(size = 10, color = "blue", face = "bold"),
    plot.subtitle = element_text(size = 6),
    legend.title=element_blank(),
    legend.text = element_text(size = 6),
    legend.position = "bottom")
p1
```

Question 2
=======================================================================

Inputs {.sidebar}
-----------------------------------------------------------------------

#### <b>Question 2</b>

How can I check if my resting heart rate is normal?

According to American Heart Association, "resting heart rate is the heart pumping the lowest amount of blood you need because you’re not exercising. If you’re sitting or lying and you’re calm, relaxed and aren’t ill, your heart rate is normally between 60 (bpm) and 100 (bpm)."

Figure 2 visualizes my resting heart rate data (beats per minute) from 11/1/22 to 11/30/22. From the graph, my average resting heart rate is 96.5 bpm which is within range of 60-100 bpm. However, the trend is decreasing. So, I should keep monitoring the data every month.


Column
-----------------------------------------------------------------------

### Figure 2
```{r}
DF2 <- read.csv("Resting Heart Rate Data1.csv")
DF2$Date <- as.Date(DF2$Date, format = "%m/%d/%Y")
p2 <- ggplot(DF2, aes(x = Date, y = RestingHR)) +
  geom_point(color = "Skyblue3", alpha = 0.75) +
  geom_smooth(method = lm) +
  labs(
    x = "Date",
    y = "Resting Heart Rate (bpm)",
    title = "Monthly Resting Heart Rate Data - November 2022",
    subtitle = "Data source: Apple Watch") +
  theme_light() +
  theme(
    axis.ticks = element_blank(),
    axis.text = element_text(size = 6),
    axis.title = element_text(size = 6),
    plot.title = element_text(size = 10, color = "blue", face = "bold"),
    plot.subtitle = element_text(size = 6))
p2
```

Question 3
=======================================================================

Inputs {.sidebar}
-----------------------------------------------------------------------

#### <b>Question 3</b>

Do I have normal active energy calories per day?

Active calorie numbers are what is burned throughout the day only while doing physical, non-sedentary activities such as walking or working out. Apple Watch uses personal information — such as your height, weight, gender and age — to calculate how many calories burn and other daily activity metrics.

Figure 3 shows the active energy data per day from 11/1/22 to 11/30/22. From the graph, my average resting heart rate is 351.03 kcal which is lower than normal range of 400-600 kcal/day) So, I should increase more physical activities per day to improve my daily active energy. However, this data does not include the active energy when not wearing apple watch.


Column
-----------------------------------------------------------------------

### Figure 3
```{r}
DF3 <- read.csv("Active Energy Data1.csv")
DF3$Date <- as.Date(DF3$Date, format = "%m/%d/%Y")
p3 <- ggplot(DF3, aes(x = Date, y = Active.Energy)) +
  geom_step(color = "orange") +
  geom_rect(aes(xmin = Date, xmax = lead(Date), 
                ymin = 0, ymax = Active.Energy), fill = "orange", alpha = 0.5) +
  geom_smooth(se = FALSE, color = "red", alpha = 0.25, linetype = "dashed") +
  labs(
    x = "Date",
    y = "Active Energy (kcal)",
    title = "Monthly Active Energy Data - November 2022",
    subtitle = "Data source: Apple Watch") +
  theme_light() +
  theme(
    axis.ticks = element_blank(),
    axis.text = element_text(size = 6),
    axis.title = element_text(size = 6),
    plot.title = element_text(size = 10, color = "blue", face = "bold"),
    plot.subtitle = element_text(size = 6))
p3
```

Question 4
=======================================================================

Inputs {.sidebar}
-----------------------------------------------------------------------

#### <b>Question 4</b>

How can I check if my average step is normal?

Since walking and moving are related to the active energy burned per day, visualizing the step count data will shows how to improve this health indicator. This data was collected by Apple Watch and iPhone using an accelerometer that measures total body movement to track activity.

According to Thom Rieck, the average American walks 3,000 to 4,000 steps a day, or roughly 1.5 to 2 miles. Figure 4 shows how many steps a day I walked in November as my own baseline comparing to the average of 3,000 - 4,000 per day. My average walks in November is 6,214.33 steps which is more than average American walks, but still less than
recommended steps (7,000 per day). Therefore, I should aim to increase approximately 800 more steps per day for better health.


Column
-----------------------------------------------------------------------

### Figure 4
```{r}
DF4 <- read.csv("Step Count Data1.csv")
DF4$Date <- as.Date(DF4$Date, format = "%m/%d/%Y")
p4 <- ggplot(DF4, aes(x = Date, y = Step.Count)) +
  geom_bar(stat="identity", width = 0.5, fill="tomato2") +
  geom_line(aes(x = Date, y = 7000, color = "Recommended per day (7,000 steps)")) +
  scale_y_continuous(limits = c(0,12000), expand = c(0,0)) +
  geom_ribbon(aes(x = Date,
                  ymin = 3000,
                  ymax = 4000,
                  fill = "Average American Walks (3,000-4,000 steps)"),
              alpha = 0.25,
              color = NA) +
  labs(
    x = "Date",
    y = "Step Count (count)",
    title = "Monthly Step Count Data - November 2022",
    subtitle = "Data source: Apple Watch") +
  theme_light() +
  theme(
    axis.ticks = element_blank(),
    axis.text = element_text(size = 6),
    axis.title = element_text(size = 6),
    plot.title = element_text(size = 10, color = "blue", face = "bold"),
    plot.subtitle = element_text(size = 6),
    legend.title=element_blank(),
    legend.text = element_text(size = 6),
    legend.position = "bottom")
p4
```

Question 5
=======================================================================

Inputs {.sidebar}
-----------------------------------------------------------------------

#### <b>Question 5</b>

Do I have normal average walking heart rate?

In general, walking is a low- to moderate-intensity activity. So, the heart rate should fall between 50 to 70 percent of maximum heart rate. Maximum heart rate = 220-Age = 220-32 = 188 bpm. Therefore, 50-70% of maximum heart rate = 0.5(188)-0.7(188) = 94-132 bpm.

Figure 5 shows monthly average walking heart rate from 11/1/22 to 11/30/22. My average walking heart rate this month is 94.02 which is little low compared to the recommended heart rate zone. According to as bradycardia, a slower-than-normal heart rate is not an uncommon situation. It is, however, one that your doctor will want to monitor and for which treatment may become necessary. So, this figure is important to keep tracking heart rate data to ensure it is within the normal range.

Column
-----------------------------------------------------------------------

### Figure 5
```{r}
DF5 <- read.csv("Walking Heart Rate Average Data1.csv")
DF5$Date <- as.Date(DF5$Date, format = "%m/%d/%Y")
p5 <- ggplot(DF5, aes(x = Date, y = Walking.HR.avg, label = Walking.HR.avg)) +
  geom_point(stat='identity', size = 6, color = "red2") + 
  geom_text(stat='identity', color = "white", size = 2) +
  geom_segment(aes(x = Date, 
                   xend = Date, 
                   y = 0, 
                   yend = Walking.HR.avg),
               color = "red2") + 
  scale_y_continuous(limits = c(0,160), expand = c(0,0)) +
  geom_ribbon(aes(x = Date,
                  ymin = 94,
                  ymax = 132,
                  fill = "Average Walking Heart Rate Zone (94-132 bpm)"),
              alpha = 0.25,
              color = NA) +
  labs(
    x = "Date",
    y = "Average Walking Heart Rate (bpm)",
    title = "Monthly Average Walking Heart Rate Data - November 2022",
    subtitle = "Data source: Apple Watch") +
  theme_light() +
  theme(
    axis.ticks = element_blank(),
    axis.text = element_text(size = 6),
    axis.title = element_text(size = 6),
    plot.title = element_text(size = 10, color = "blue", face = "bold"),
    plot.subtitle = element_text(size = 6),
    legend.title=element_blank(),
    legend.text = element_text(size = 6),
    legend.position = "bottom")
p5
```