Overview

1/ Project Objective:

Develop a visualization dashboard based on a series of data on personal habit analysis.

2/ Data Collection Methods:

the data has been collected from the personal wearable tech tools.

3/ The 5 Big Questions:

  1. How is the general trend of Screen time ?
  2. How does the number of floors climbed impact the relationship between steps taken and distance covered?
  3. how these steps, distance, and floors impact sleep time?
  4. Compare screen time and sleep time, is there any interesting pattern?
  5. How is the relationship between Productivity and Sleep Time?

Question 1

Column

Column {data-width=300} ### Screen time component analysis

Question 2

Column

Chart

Question 3

Column

Date

Question 4

Column

Grocery

Question 5

Column

relationship between Productivity and Sleep Time

conclusion

In conclusion, the analyses of screen time, physical activity, and productivity data reveal several notable patterns:

Screen Time and Sleep: There is an inverse relationship between screen time and sleep duration, with increased screen time generally leading to decreased sleep. However, variability and anomalies in the data suggest individual differences and the influence of external factors. High peaks in screen time warrant further investigation to identify their causes, such as work, social activities, or entertainment.

Screen Time Variability: The dynamic pattern of screen usage suggests inconsistent daily routines or varying demands. Further analysis could explore correlations with weekdays vs. weekends, holidays, or external events to better understand the drivers of screen time fluctuations.

Steps and Distance: A clear linear relationship exists between steps taken and distance covered, with the number of floors climbed adding another layer of insight. Higher steps correlate with greater distances, but the number of floors climbed shows only a slight positive trend. Variability in steps and floors climbed indicates diverse exercise routines or environments.

Productivity and Sleep: There is a general negative correlation between productivity and sleep time, suggesting that higher productivity may come at the expense of sleep. The limited data points and variability imply that additional factors need to be considered, and more comprehensive data collection is necessary to draw definitive conclusions.

Overall, these analyses highlight the need for deeper investigation into the underlying causes and implications of these patterns. Understanding the relationships between screen time, physical activity, productivity, and sleep can inform strategies to improve well-being and optimize daily routines.

---
title: "ANLY 512 - Final Project"
author: "Ruoyuan Ma"
output: 
  flexdashboard::flex_dashboard:
    orientation: columns
    vertical_layout: fill
    source_code: embed
---

```{r setup, include=FALSE}

library(flexdashboard)
library(lubridate)
library(dplyr)
library(plotly)
library(DT)
library(chron)
library(dygraphs)
library(xts)
library(reshape2)
library(gridExtra)
library(cowplot)
library(readr)
library(scales)
library(ggthemes)

Habittracker <- read_csv("health data.csv")
```

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

1/ Project Objective:

Develop a visualization dashboard based on a series of data on personal habit analysis.

2/ Data Collection Methods:

the data has been collected from the personal wearable tech tools.

3/ The 5 Big Questions:

1. How is the general trend of Screen time ?
2. How does the number of floors climbed impact the relationship between steps taken and distance covered?
3. how these steps, distance, and floors impact sleep time?
4. Compare screen time and sleep time, is there any interesting pattern?
5. How is the relationship between Productivity and Sleep Time?

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

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

### Screen time component analysis

The highest peaks could indicate specific events or activities leading to increased screentime. It might be useful to investigate what caused these peaks—whether they are work-related, social, entertainment, or other activities.
The variability in screentime suggests a dynamic pattern of screen usage. High variability might indicate inconsistent daily routines or varying demands on screen usage.Further analysis could explore potential correlations between high screentime days and other factors such as weekday vs. weekend, specific dates (e.g., holidays), or even external factors like weather or events. The chart provides a clear visualization of how screentime fluctuates over a period. The significant peaks and troughs highlight the need for deeper analysis to understand the underlying causes and implications of these patterns on overall well-being and productivity.



Column {.tabset}
-------------------------------------

  
Column {data-width=300}
### Screen time component analysis

```{r}
library(plotly)
library(readr)
library(dplyr)
Habittracker <- Habittracker %>%
  mutate(Date = as.Date(Date, format = "%d-%b"))
         
Habittracker <- Habittracker %>%
  mutate(screentime = as.numeric(screentime),
         `except social` = as.numeric(`except social`),
         Social = as.numeric(Social))



# Create the plot
plot_ly(Habittracker, x = ~Date, y = ~screentime, type = 'scatter', mode = 'lines',
        line = list(color = 'transparent'),
        showlegend = FALSE, name = 'Total screentime') %>%
  add_trace(x = ~Date, y = ~`except social`, type = 'scatter', mode = 'lines',
            fill = 'tonexty', fillcolor='rgba(0,100,80,0.2)', line = list(color = 'transparent'),
            showlegend = FALSE, name = 'Screentime Except Social') %>%
  add_trace(x = ~Date, y = ~Social, type = 'scatter', mode = 'lines',
            line = list(color='rgb(0,100,80)'),
            name = 'Social screentime') %>%
  layout(title = "Screentime Component Analysis",
         paper_bgcolor='rgb(255,255,255)', plot_bgcolor='rgb(229,229,229)',
         xaxis = list(title = "Date",
                      gridcolor = 'rgb(255,255,255)',
                      showgrid = TRUE,
                      showline = FALSE,
                      showticklabels = TRUE,
                      tickcolor = 'rgb(127,127,127)',
                      ticks = 'outside',
                      zeroline = FALSE),
         yaxis = list(title = "Minutes",
                      gridcolor = 'rgb(255,255,255)',
                      showgrid = TRUE,
                      showline = FALSE,
                      showticklabels = TRUE,
                      tickcolor = 'rgb(127,127,127)',
                      ticks = 'outside',
                      zeroline = FALSE))



```

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

Inputs {.sidebar}
-------------------------------------
### Question 2
How does the number of floors climbed impact the relationship between steps taken and distance covered?

The scatter plot visualizes the relationship between steps taken (on the x-axis) and distance covered (on the y-axis) for daily health tracking, with the color gradient representing the number of floors climbed.

There is a clear linear relationship between steps taken and distance covered. As the number of steps increases, the distance covered also increases proportionally. The color gradient, ranging from dark purple (0 floors) to yellow (6+ floors), indicates the number of floors climbed. The number of floors climbed does not have a strong direct correlation with distance for lower steps, as indicated by the mixed colors. However, as steps increase, the number of floors climbed seems to have a slight positive trend with distance. For users with higher physical activity (indicated by higher steps), the variation in floors climbed suggests different exercise routines or environments (e.g., walking vs. hiking).


Column
-------------------------------------
    
### Chart
```{r}
plot_ly(
  data = Habittracker,
  x = ~step,
  y = ~distance,
  color = ~floors,
  hoverinfo = 'text',
  text = ~paste(
    'Steps: ', step,
    'Distance: ', distance,
    'Floors: ', floors,
    'Date: ', Date
  ),
  mode = "markers",
  marker = list(size = 17)
) %>%
  layout(
    xaxis = list(title = "Steps/K"),
    yaxis = list(title = "Distance/KM"),
    title = "Daily Health Check"
  )
```

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

Inputs {.sidebar}
-------------------------------------
### Question 3

how these steps, distance, and floors impact sleep time.
This graph is conducted with ggplot and ploty.

There are notable clusters of data points around certain values of steps, distance, and floors. Most data points seem to cluster around the 3 to 4 range for floors and between 2k to 6k for steps. There appears to be a general trend where higher distances correlate with higher steps, but this isn't strictly linear. Floors do not show a clear correlation with steps or distance, as there are high floor values with relatively low steps and distance, and vice versa. In general individuals with moderate activity levels (2k to 6k steps) are represented the most. High activity levels (close to 10k steps) are less frequent. There is variability in the number of floors climbed, with a significant number of activities involving fewer floors climbed. The plot indicates that a certain number of steps does not always correspond to a proportional increase in distance, possibly due to differences in stride length or terrain.


Column {.tabset}
-------------------------------------
    
### Date


```{r}
plot_ly(Habittracker, x = ~step, y = ~distance, z = ~`floors`, colors = c('#BF382A', '#0C4B8E'),hoverinfo = 'text',
        text = ~paste('Steps: ', Habittracker$Step, 
                      ' Distance: ', Habittracker$Distance,
                      ' Floors: ', Habittracker$`floors`,
                      ' Date: ', Habittracker$Date),mode = "markers",marker = list(size = 10)) %>%
  add_markers() %>%
  
  layout(title = "Correlation between steps, distance and Sleeptime",
    scene = list(xaxis = list(title = 'Steps'),
                     yaxis = list(title = 'Distance'),
                     zaxis = list(title = 'Floors')))


```

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

Inputs {.sidebar}
-------------------------------------
### Question 4

Compare screen time and sleep time, is there any interesting pattern?

This graph utilizes ggplot. There appears to be an inverse relationship between screen time and sleep time, where increased screen time often correlates with decreased sleep time. The relationship could be more perfectly linear, indicating variability in how screen time impacts sleep time. While the general trend suggests more screen time correlates with less sleep, there are anomalies and spikes indicating other factors might be influencing sleep duration. There are fluctuations in sleep time even at similar levels of screen time, indicating individual differences in how screen time affects sleep.


Column {.tabset}
-------------------------------------
    
### Grocery
```{r}
library(ggplot2)
library(plotly)
# Load your dataset
# Replace "path_to_your_file.csv" with the actual path to your CSV file
Habittracker <- read_csv("C:/Users/RuoyuanMa/Downloads/health data.csv")

# Create a ggplot object
p <- ggplot(Habittracker, aes(x = screentime, y = sleeptime)) +
  geom_line() +
  labs(title = "Correlation between Screen Time and Sleep Time",
       x = "Screen Time",
       y = "Sleep Time")

# Convert to interactive plotly object
interactive_plot <- ggplotly(p)

# Display the interactive plot
interactive_plot

```



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

Inputs {.sidebar}
-------------------------------------
### Question 5
 relationship between Productivity and Sleep Time

 There appears to be a general negative correlation between productivity and sleep time. As productivity scores increase, sleep time tends to decrease. The plot shows a sparse distribution with a limited number of data points, which might affect the reliability of any inferred trends. There are no clear clusters, indicating variability in the relationship. This analysis provides an initial understanding, but more data and a deeper investigation are necessary to draw definitive conclusions.



Column
-------------------------------------
    
###  relationship between Productivity and Sleep Time
```{r}
library(ggplot2)
library(plotly)
# Load the dataset

Habittracker <- read_csv("C:/Users/RuoyuanMa/Downloads/health data.csv")
plot_ly(Habittracker, x = ~productivity, y = ~sleeptime, type = 'scatter', mode = 'markers') %>%
  layout(
    title = "Relationship between Productivity and Sleep Time",
    xaxis = list(title = "Productivity Score"),
    yaxis = list(title = "Sleep Time (minutes)")
  )

```


### conclusion

In conclusion, the analyses of screen time, physical activity, and productivity data reveal several notable patterns:

Screen Time and Sleep: There is an inverse relationship between screen time and sleep duration, with increased screen time generally leading to decreased sleep. However, variability and anomalies in the data suggest individual differences and the influence of external factors. High peaks in screen time warrant further investigation to identify their causes, such as work, social activities, or entertainment.

Screen Time Variability: The dynamic pattern of screen usage suggests inconsistent daily routines or varying demands. Further analysis could explore correlations with weekdays vs. weekends, holidays, or external events to better understand the drivers of screen time fluctuations.

Steps and Distance: A clear linear relationship exists between steps taken and distance covered, with the number of floors climbed adding another layer of insight. Higher steps correlate with greater distances, but the number of floors climbed shows only a slight positive trend. Variability in steps and floors climbed indicates diverse exercise routines or environments.

Productivity and Sleep: There is a general negative correlation between productivity and sleep time, suggesting that higher productivity may come at the expense of sleep. The limited data points and variability imply that additional factors need to be considered, and more comprehensive data collection is necessary to draw definitive conclusions.

Overall, these analyses highlight the need for deeper investigation into the underlying causes and implications of these patterns. Understanding the relationships between screen time, physical activity, productivity, and sleep can inform strategies to improve well-being and optimize daily routines.