<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Mario Demetriou on Medium]]></title>
        <description><![CDATA[Stories by Mario Demetriou on Medium]]></description>
        <link>https://medium.com/@mariodemetriou?source=rss-b5d80b5275d7------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*8YpK7OzBO-Jtbbpmlbbwbw.jpeg</url>
            <title>Stories by Mario Demetriou on Medium</title>
            <link>https://medium.com/@mariodemetriou?source=rss-b5d80b5275d7------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 18 Nov 2026 04:26:18 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@mariodemetriou/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Move, Sleep, and Burn: What Fitbit Data Reveals About Our Daily Wellbeing]]></title>
            <link>https://medium.com/@mariodemetriou/move-sleep-and-burn-what-fitbit-data-reveals-about-our-daily-wellbeing-e5e22cb524b1?source=rss-b5d80b5275d7------2</link>
            <guid isPermaLink="false">https://medium.com/p/e5e22cb524b1</guid>
            <category><![CDATA[health]]></category>
            <category><![CDATA[fitness]]></category>
            <category><![CDATA[data-visualization]]></category>
            <category><![CDATA[sleep]]></category>
            <category><![CDATA[fitbit]]></category>
            <dc:creator><![CDATA[Mario Demetriou]]></dc:creator>
            <pubDate>Fri, 06 Dec 2024 08:41:59 GMT</pubDate>
            <atom:updated>2024-12-06T08:41:59.207Z</atom:updated>
            <content:encoded><![CDATA[<h3>Executive Summary</h3><p>The journey to wellness is full of data — steps, calories, sleep. By analyzing Fitbit data, I set out to uncover patterns that reveal how these day-to-day metrics interconnect. I was curious: Does the day of the week impact our activity levels? How does the number of steps we take influence calories burned? Do our sleep habits vary based on routine? This analysis reveals insights into how daily activities shape our health, highlighting opportunities for personalized interventions and informed decisions for a healthier lifestyle.</p><h3>Background Information &amp; Data Summary</h3><p>The dataset used in this analysis was sourced through Kaggle and titled <a href="https://www.kaggle.com/datasets/arashnic/fitbit/data">“FitBit Fitness Tracker Data”</a>. It was generated by 33 anonymous Fitbit users that responded to a distributed survey through Amazon’s <a href="https://www.mturk.com/">Mechanical Turk</a> between 03.12.2016–05.12.2016, containing real activity data and includes information on:</p><ul><li>Daily Steps</li><li>Calories Burned</li><li>Sleep Duration</li><li>Hourly Activity Intensity</li></ul><p>The dataset has over 30,000 records of daily activity from various users. This type of data is becoming more accessible, and I’m personally interested because I track my own fitness journey using a Garmin watch. Working with this data gave me a chance to explore how real-world health data could be leveraged to build behavior-based interventions — something that aligns with some app ideas I have in mind.</p><h3>Why This Dataset?</h3><p>Being an avid fitness tracker, I’ve always been curious about the patterns hidden in my own exercise and sleep data. With this Fitbit dataset, I got to look at how behaviors might be similar or different across a broader group of users. Not only was I intrigued about the trends within activity and sleep, but I also wanted to experiment with a dataset that could inspire potential business ideas — apps or services that use behavioral insights to drive healthier habits.</p><h3>Analysis and Visualizations</h3><h4>1. Loading the libraries, reading the datasets, inspecting the data structures and pre-processing the data</h4><pre># Load Libraries<br># These libraries will be used to create visualizations and manipulate the dataset.<br>library(dplyr)          # For data manipulation<br>library(ggpubr)         # For creating visualizations (bar plots, scatter plots, etc.)<br>library(ggeasy)         # For making easy tweaks to plots<br>library(ggplot2)        # General plotting library<br>library(lubridate)      # For handling dates<br>library(scales)         # For formatting axis labels (e.g., adding dollar signs or commas)<br>library(readr)          # For reading CSV files<br>library(smallstuff)     # For outliers()<br>library(sur)            # For enhanced ggplot2 visualizations</pre><pre># Loading required files from the Fitbit dataset<br>df_daily_activity &lt;- read.csv(&quot;./data/dailyActivity_merged.csv&quot;)  <br>df_sleep &lt;- read.csv(&#39;./data/sleepDay_merged.csv&#39;)                <br>weight_data &lt;- read_csv(&quot;./data/weightLogInfo_merged.csv&quot;)        <br>df_hourly_activity &lt;- read.csv(&#39;./data/hourlyIntensities_merged.csv&#39;) </pre><pre>### Inspecting the structure of the data<br># Count distinct values in the &quot;Id&quot; column<br>distinct_weight_ids &lt;- n_distinct(weight_data$Id)<br>print(distinct_weight_ids) # Only 8 unique users in the weight data so I wont be using this file/dataset<br><br># unique values in the Id column<br>unique(df_hourly_activity$Id)<br># count of unique values in the Id column<br>length(unique(df_hourly_activity$Id)) # 33 unique users in the hourly activity data<br><br># Inspect the structure and summary of the data<br># This helps us understand the available variables in the dataset.<br>str(df_daily_activity) # structure of the daily activity data<br># ActivityDate is in the format of &quot;mm/dd/yyyy&quot; -&gt; will need to fix this<br># Everything else is numeric<br><br><br>summary(df_daily_activity) # summary of the daily activity data</pre><pre>### Data Preprocessing<br># Convert Date columns to a Date format<br># The dataset has a date column in &#39;ActivityDate&#39; and &#39;SleepDay&#39;.<br>df_daily_activity &lt;- df_daily_activity %&gt;%<br>  mutate(ActivityDate = mdy(ActivityDate)) # -&gt; it worked, hooray<br><br>df_sleep &lt;- df_sleep %&gt;%<br>  mutate(SleepDay = mdy_hms(SleepDay)) # convert SleepDay to a date format<br><br># Merge sleep and activity data on date and user ID (a common &#39;Id&#39; field exists)<br>df_combined &lt;- df_daily_activity %&gt;%<br>  inner_join(df_sleep, by = c(&quot;Id&quot;, &quot;ActivityDate&quot; = &quot;SleepDay&quot;))</pre><h4>2. Average Calories Burned by Day of the Week</h4><figure><img alt="This bar graph, titled “Gold, Silver, Bronze: Which Day Burns the Most Calories?”, shows average calories burned by day of the week for Fitbit users. Tuesday has the highest average, marked in gold, followed by Friday in bronze, and Saturday in silver. Light grey bars represent other days. A dashed black line shows the overall average calories burned. The x-axis lists days (Monday to Sunday), while the y-axis displays Average Calories Burned (2,000 to 2,400). Tuesday shows the highest activity." src="https://cdn-images-1.medium.com/max/947/0*9Lbw_C1MnKgPVGLm" /></figure><p><strong>Key Findings:</strong></p><ul><li>Tuesday was the most active day, earning the Gold, while Friday took Bronze and Saturday came in second.</li><li>The average calorie expenditure was surprisingly consistent, indicating that weekday routines play a big role in maintaining activity levels, more so than weekends.</li></ul><p><strong>Code (in R):</strong></p><pre># Visualization 1: Bar plot showing average calories burned for each day of the <br># week, with custom colors and mean line.<br><br>### Data Pre-processing<br># Calculate the average calories burned for each day of the week<br>df_calories_weekday &lt;- df_daily_activity %&gt;% <br>  mutate(Weekday = weekdays(ActivityDate)) %&gt;% # Extract the weekday from the date<br>  mutate(Weekday = factor(Weekday, levels = c(&quot;Monday&quot;, &quot;Tuesday&quot;, &quot;Wednesday&quot;, <br>                                              &quot;Thursday&quot;, &quot;Friday&quot;, &quot;Saturday&quot;, <br>                                              &quot;Sunday&quot;))) %&gt;%  # Specify the order of the days<br>  group_by(Weekday) %&gt;%<br>  summarise(avg_calories = mean(Calories, na.rm = TRUE))<br><br># Identify which day has the highest, second highest, and third highest calories <br># burned.<br>top_days &lt;- df_calories_weekday %&gt;%<br>  arrange(desc(avg_calories)) %&gt;%<br>  # Mutate a new column &#39;color&#39; based on the ranking of the days<br>  mutate(color = case_when( <br>    row_number() == 1 ~ &quot;Gold&quot;, # Assign Gold to the top day<br>    row_number() == 2 ~ &quot;Silver&quot;, # Assign Silver to the second day<br>    row_number() == 3 ~ &quot;Bronze&quot;, # Assign Bronze to the third day<br>    TRUE ~ &quot;Grey&quot; # Assign Grey to the rest<br>  )) <br><br># Calculate the mean calories burned for adding the reference line<br>mean_calories &lt;- mean(df_calories_weekday$avg_calories, na.rm = TRUE)<br># Mean calories burned are 2304.59<br><br># Convert &#39;color&#39; to a factor with levels in the correct order<br>top_days$color &lt;- factor(top_days$color, levels = c(&quot;Gold&quot;, &quot;Silver&quot;, &quot;Bronze&quot;, &quot;Grey&quot;))</pre><pre># Plotting the bar plot with custom colors, mean line, and y-axis limits for a more focused view<br>ggplot(top_days, aes(x = Weekday, y = avg_calories, fill = color)) +<br>  geom_bar(stat = &quot;identity&quot;) +<br>  geom_hline(yintercept = mean(top_days$avg_calories, na.rm = TRUE), linetype = &quot;dashed&quot;, color = &quot;black&quot;) +  # Add a dashed line for mean<br>  scale_fill_manual(values = c(&quot;Gold&quot; = &quot;gold&quot;, &quot;Silver&quot; = &quot;slategray&quot;, &quot;Bronze&quot; = &quot;saddlebrown&quot;, &quot;Grey&quot; = &quot;lightgrey&quot;)) +<br>  labs(<br>    title = &quot;Gold, Silver, Bronze: Which Day Burns the Most Calories?&quot;,<br>    subtitle = &quot;Fitbit users show consistent activity throughout the week with weekends remaining high; weekdays <br>compete for the top spot. Tuesday takes Gold.&quot;,<br>    x = &quot;Day of Week&quot;,<br>    y = &quot;Average Calories Burned&quot;<br>  ) +<br>  coord_cartesian(ylim = c(2000, 2400)) +  # Use coord_cartesian to set y-axis limits without removing data<br>  scale_y_continuous(breaks = seq(0, 2400, by = 100), labels = comma) +  # Set breaks every 100 calories<br>  theme_minimal() +<br>  theme(<br>    legend.position = &quot;none&quot;,<br>    plot.title = element_text(<br>      size = 18,          # Increase font size for prominence<br>      face = &quot;bold&quot;,      # Make the title bold<br>      color = &quot;black&quot;, # Use a striking color to make the title stand out<br>    ),<br>    plot.subtitle = element_text(<br>      size = 12,          # Set a slightly smaller font size for the subtitle<br>      # face = &quot;italic&quot;,    # Use italic to differentiate it from the title - Removed - Didnt like the look<br>      # hjust = 0.5,        # Center the subtitle - I didnt like the center alignment. <br>                            # It&#39;s against the guidelines of our textbook<br>      # margin = margin(b = 15)  # Add space below the subtitle for separation - removed<br>    ),<br>    axis.title.x = element_text(size = 12, face = &quot;bold&quot;),<br>    axis.title.y = element_text(size = 12, face = &quot;bold&quot;)<br>  )</pre><h4>3. Sleep Patterns by Day of the Week</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/947/0*nWfFyrEk_Tx74n6r" /></figure><p><strong>Key Findings:</strong></p><ul><li>Weekends lead to longer sleep durations, possibly showing people catching up on rest.</li><li>Wednesday also emerged as a significant rest day, surprisingly ranking second in sleep duration.</li></ul><p><strong>Code(in R):</strong></p><pre># Visualization 2: Box plot showing sleep duration by day of the week, <br># with custom colors for top days.<br><br># Preprocessing<br># Convert sleep day data to proper date format and extract day of the week<br>df_sleep &lt;- df_sleep %&gt;%<br>  mutate(Weekday = weekdays(SleepDay)) %&gt;%<br>  mutate(Weekday = factor(Weekday, levels = c(&quot;Monday&quot;, &quot;Tuesday&quot;, &quot;Wednesday&quot;, &quot;Thursday&quot;, &quot;Friday&quot;, &quot;Saturday&quot;, &quot;Sunday&quot;)))  # Specify day order<br><br># Summarize average sleep duration by day of the week<br>avg_sleep_duration &lt;- df_sleep %&gt;%<br>  group_by(Weekday) %&gt;%<br>  summarise(avg_duration = mean(TotalMinutesAsleep, na.rm = TRUE)) %&gt;%<br>  mutate(avg_duration_hours = avg_duration / 60) # Convert minutes to hours<br><br># Identify top days (gold, silver, bronze)<br>top_sleep_days &lt;- avg_sleep_duration %&gt;%<br>  arrange(desc(avg_duration)) %&gt;%<br>  mutate(color = case_when(<br>    row_number() == 1 ~ &quot;Gold&quot;,<br>    row_number() == 2 ~ &quot;Silver&quot;,<br>    row_number() == 3 ~ &quot;Bronze&quot;,<br>    TRUE ~ &quot;Grey&quot;<br>  ))<br><br># Merge back with original data to assign colors<br>df_sleep &lt;- df_sleep %&gt;%<br>  left_join(top_sleep_days, by = &quot;Weekday&quot;)</pre><pre># Box plot showing sleep duration by day of the week<br>ggplot(df_sleep, aes(x = Weekday, y = TotalMinutesAsleep, fill = color)) +<br>  geom_boxplot(alpha = 0.8) +  # Box plot with no outliers and some transparency<br>  scale_fill_manual(values = c(&quot;Gold&quot; = &quot;gold&quot;, &quot;Silver&quot; = &quot;slategray&quot;, <br>                               &quot;Bronze&quot; = &quot;saddlebrown&quot;, &quot;Grey&quot; = &quot;lightgrey&quot;)) +<br>  labs(<br>    title = &quot;Weekend Wins: How Sleep Patterns Vary Across the Week&quot;,<br>    subtitle = &quot;Rest is longer on the weekends, with Saturday and Sunday showing higher average sleep-<br>illustrating a pattern of catch-up sleep. Wednesday surprisingly grabbing the Silver!&quot;,<br>    x = &quot;Day of Week&quot;,<br>    y = &quot;Total Minutes Asleep&quot;<br>  ) +<br>  theme_minimal() +<br>  theme(<br>    legend.position = &quot;none&quot;, # Remove the legend to reduce unnecessary clutter<br>    plot.title = element_text(<br>      size = 18,<br>      face = &quot;bold&quot;,<br>      color = &quot;black&quot;<br>    ),<br>    plot.subtitle = element_text(<br>      size = 12,<br>    ),<br>    axis.title.x = element_text(size = 12, face = &quot;bold&quot;), # Increase axis title font size<br>    axis.title.y = element_text(size = 12, face = &quot;bold&quot;)<br>  )# Box plot<br>ggplot(df_sleep, aes(x = Weekday, y = TotalMinutesAsleep, fill = color)) +<br>  geom_boxplot() +<br>  labs(title = &quot;Weekend Wins: How Sleep Patterns Vary Across the Week&quot;,<br>       subtitle = &quot;Saturday and Sunday show higher sleep duration; Wednesday surprisingly grabs Silver!&quot;)</pre><h4>4. Activity Intensity by Hour of the Day</h4><figure><img alt="This image shows a heatmap titled “The Golden Hour: When Does Activity Reach Its Highest?”. It displays Average Intensity throughout the day, highlighting periods of highest activity for Fitbit users. The x-axis represents the Hour of Day, from 0 to 24, while the y-axis shows Average Intensity. Yellow tiles indicate periods of higher intensity, occurring mostly in the afternoon and early evening, while grey tiles represent low activity during early morning hours." src="https://cdn-images-1.medium.com/max/947/0*SVdX4ZQmDJa-fIgp" /></figure><p><strong>Key Findings:</strong></p><ul><li>Activity levels peak in the afternoon and early evening hours.</li><li>Knowing when people are naturally most active can help schedule activities that align with energy peaks.</li></ul><p><strong>Code (in R):</strong></p><pre># Visualization 3: Heatmap to visualize activity intensity throughout the day.<br><br># Process the data to extract the hour from the datetime column<br>df_hourly_activity &lt;- df_hourly_activity %&gt;%<br>  mutate(ActivityHour = mdy_hms(ActivityHour)) %&gt;%  # Convert date and time column<br>  mutate(Hour = hour(ActivityHour))  # Extract hour from datetime<br><br># Create a heatmap for average activity intensity by hour of day<br>df_hourly_activity %&gt;%<br>  group_by(Hour) %&gt;%<br>  summarise(avg_intensity = mean(TotalIntensity, na.rm = TRUE)) %&gt;%<br>  ggplot(aes(xmin = Hour - 0.5, xmax = Hour + 0.5, ymin = avg_intensity - 0.5, <br>             ymax = avg_intensity + 0.5, fill = avg_intensity)) +<br>  geom_rect(color = NA, linewidth = 1) +  # Use geom_rect with custom boundaries and color<br>  scale_fill_gradient(low = &quot;lightgrey&quot;, high = &quot;gold&quot;, space = &quot;Lab&quot;) +  # Matching the color scheme with gold<br>  labs(<br>    title = &quot;The Golden Hour: When Does Activity Reach Its Highest?&quot;,<br>    subtitle = &quot;Early morning starts slow, but afternoons and early evenings see the highest intensity—highlighting <br>daily energy patterns and prime hours of movement.&quot;,<br>    x = &quot;Hour of Day&quot;,<br>    y = &quot;Average Intensity&quot;  <br>  ) +<br>  theme_minimal() +<br>  theme(<br>    legend.position = &quot;none&quot;,  # Remove the legend to reduce unnecessary clutter<br>    plot.title = element_text(  <br>      size = 18,          # Increase font size for prominence<br>      face = &quot;bold&quot;,      # Make the title bold<br>      color = &quot;black&quot;, <br>    ),<br>    plot.subtitle = element_text(<br>      size = 12,          <br>    ),<br>    axis.title.x = element_text(size = 12, face = &quot;bold&quot;), # Increase axis title font size<br>    axis.title.y = element_text(size = 12, face = &quot;bold&quot;)<br>  )</pre><h4>5. Steps vs. Calories Burned</h4><figure><img alt="This image is a scatter plot titled “The More You Move, The More You Burn: Steps vs. Calories”, showing the relationship between Total Daily Steps and Calories Burned for Fitbit users. Yellow dots represent individual data points, with a golden trend line indicating a positive linear correlation — more steps lead to more calories burned. The x-axis shows Total Daily Steps, and the y-axis represents Calories Burned, highlighting the impact of increased activity on calorie expenditure." src="https://cdn-images-1.medium.com/max/947/0*rIJS8VxKXaYCIHxK" /></figure><p><strong>Key Findings:</strong></p><ul><li>A clear linear relationship between steps taken and calories burned was observed.</li><li>More steps lead to more calories burned, confirming intuitive insights.</li></ul><p><strong>Code (in R):</strong></p><pre># Visualization 4: Scatter plot showing the relationship between Total Daily Steps and Calories Burned, with a linear trend line.<br>ggplot(df_daily_activity, aes(x = TotalSteps, y = Calories)) +<br>  geom_point(color = &quot;gold&quot;, alpha = 0.6, size = 1.5) +  # Scatter plot points with gold color<br>  geom_smooth(method = &quot;lm&quot;, color = &quot;darkgoldenrod&quot;, fill = &quot;lightgoldenrodyellow&quot;, se = TRUE, linewidth = 1) +  # Linear trend line with matching colors<br>  labs(<br>    title = &quot;The More You Move, The More You Burn: Steps vs. Calories&quot;,<br>    subtitle = &quot;A clear linear relationship reveals how daily steps translate into increased calorie burn—making <br>movement an essential part of health.&quot;,<br>    x = &quot;Total Daily Steps&quot;,<br>    y = &quot;Calories Burned&quot;<br>  ) +<br>  theme_minimal() +<br>  scale_x_continuous(labels = comma) +  # Format x-axis with comma separator<br>  scale_y_continuous(labels = comma) +  # Format y-axis with comma separator +<br>  theme(<br>    plot.title = element_text(<br>      size = 18,<br>      face = &quot;bold&quot;,<br>      color = &quot;black&quot;<br>    ),<br>    plot.subtitle = element_text(<br>      size = 12,<br>    ),<br>    axis.title.x = element_text(size = 12, face = &quot;bold&quot;),<br>    axis.title.y = element_text(size = 12, face = &quot;bold&quot;)<br>  )</pre><h3>The Combined Figure</h3><figure><img alt="This handout image features four data visualizations from Fitbit activity and sleep data. Each chart is designed to illustrate daily patterns in fitness metrics like calories burned, activity intensity &amp; sleep duration. Key highlights include which days of the week have the most calories burned, most sleep, and insights into steps vs. calories burned. The data is presented in gold, silver, bronze colors to emphasize top-performing categories, supported by clear titles &amp; informative subtitles." src="https://cdn-images-1.medium.com/max/1024/1*2p6epRmBUojFw9efwXAZaw.png" /></figure><p>The visualizations together tell a holistic story of how our routines — both daily and weekly — impact our health:</p><ul><li>Consistency is key for calorie burning, with weekdays often outperforming weekends.</li><li>The afternoon is when our bodies naturally prefer to move, and weekends are for catching up on sleep.</li><li>More steps mean more calories burned, but adding context like when we’re most active can help optimize routines.</li></ul><h3>Design Choices</h3><p>I was guided by the principles outlined in <a href="https://www.storytellingwithdata.com/">Storytelling with Data</a> by Cole Nussbaumer Knaflic:</p><ul><li>Focus on the Key Message: Each graph had a specific question in mind, and I kept non-relevant elements to a minimum to drive the point home.</li><li>Visual Consistency: The color scheme reflects a gold, silver, bronze theme to signify top performance, helping viewers instantly see standout days.</li><li>Minimize Chart Junk: I used minimalist themes to avoid distracting clutter, ensuring that my charts were easy to interpret.</li></ul><p>I also took inspiration from <a href="https://amzn.to/4gnwRcA">The Truthful Art by Alberto Cairo</a>:</p><ul><li>Truthfulness: The graphs accurately represented trends and relationships without over-exaggeration.</li><li>Functionality: Every design element was added to improve understanding — like the dashed line indicating average calories or the emphasis colors used for weekends.</li></ul><h3>How This Analysis Helps</h3><p>This analysis provides insights into how different activities and habits impact overall wellness. It can help individuals and companies working in the health sector optimize their offerings, whether through suggesting best times for physical activity, promoting consistent weekday routines, or providing tailored advice for sleep recovery.</p><h3>Difficulties and Challenges</h3><ul><li>Data Limitations: With only 33 participants, the dataset may not generalize to the broader population.</li><li>Data Cleaning: Dates needed conversion and merging datasets was challenging due to different formats.</li></ul><h3>Future Work</h3><ul><li>Demographic Analysis: Adding details like age, gender, or weight would help create more personalized insights.</li><li>Seasonal Trends: Exploring how activity varies with seasons or holidays would be insightful for planning and marketing health programs.</li></ul><p>Hope you enjoyed this journey through the data! Let’s keep making fitness smarter and better.</p><h3>Acknowledgement</h3><p>Furberg, R., Brinton, J., Keating, M., &amp; Ortiz, A. (2016). Crowd-sourced Fitbit datasets 03.12.2016–05.12.2016 [Data set]. Zenodo. <a href="https://doi.org/10.5281/zenodo.53894">https://doi.org/10.5281/zenodo.53894</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e5e22cb524b1" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>