This Case Study is about the Company, Bellabeat, they have these smart devices that track a users daily activities. These smart devices can track sleep, steps, etc. The data from this case study used data from thirty consenting adults to track everything from their smart devices. Then with this data I was able to create this case study on how each person utilized their time throughout the day. The data I received was on Kaggle, and his name is Möbius. His profile link here, and This is the link to the dataset I used for this Case Study.
Everyone walks, sleeps and do everyday things and this Case study will showcase who walks more and sleeps and even just sitting around, as well as burning calories. I believe that when I did start looking into the data, there were going to be people really engaged and also others that wont be as motivated. This data will show you how each person used their time for this study.
library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr 1.1.4 ✔ readr 2.1.5
## ✔ forcats 1.0.0 ✔ stringr 1.5.1
## ✔ ggplot2 3.5.1 ✔ tibble 3.2.1
## ✔ lubridate 1.9.3 ✔ tidyr 1.3.1
## ✔ purrr 1.0.2
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag() masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(here)
## here() starts at C:/Users/Rukas_000/Documents/School/Course 8/Portfolio/Case Study_2024_10
library(skimr)
library(janitor)
##
## Attaching package: 'janitor'
##
## The following objects are masked from 'package:stats':
##
## chisq.test, fisher.test
library(dplyr)
library(ggplot2)
library(tidyr)
library(shadowtext)
library(rmarkdown)
library(readr)
In the datasets available there were several data but not all of them
matched each other. There was certain data that showed a certain number
of users by their Id field. However, in the dataset there
was multiple rows of data with the same Id field. At first,
I had to make sure that there was a few datasets that had the same
amount of users in each, that has been counted at least once. Also once
that was figured out, I looked through the data, and there is a few
columns that has useful information but it was not important for the
Case Study, which is good because I can focus on more important columns
that will help.
dailyActivity_merged <- read_csv(
"C:/Users/Rukas_000/Documents/School/Course 8/Portfolio/Case Study_2024_10/mturkfitbit_export_4.12.16-5.12.16/Fitabase Data 4.12.16-5.12.16/dailyActivity_merged.csv")
## Rows: 940 Columns: 15
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (1): ActivityDate
## dbl (14): Id, TotalSteps, TotalDistance, TrackerDistance, LoggedActivitiesDi...
##
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
View(dailyActivity_merged)
sleepDay_merged <- read_csv("C:/Users/Rukas_000/Documents/School/Course 8/Portfolio/Case Study_2024_10/mturkfitbit_export_4.12.16-5.12.16/Fitabase Data 4.12.16-5.12.16/sleepDay_merged.csv")
## Rows: 413 Columns: 5
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (1): SleepDay
## dbl (4): Id, TotalSleepRecords, TotalMinutesAsleep, TotalTimeInBed
##
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
View(sleepDay_merged)
Now I am using the n_distinct() to counts the number of
unique/distinct combinations in a set of one or more vectors and then I
also used nrow function which returns the number of rows
present in a given data frame.
dailyActivity_merged %>%
select(TotalSteps,
TotalDistance,
SedentaryMinutes) %>%
summary()
## TotalSteps TotalDistance SedentaryMinutes
## Min. : 0 Min. : 0.000 Min. : 0.0
## 1st Qu.: 3790 1st Qu.: 2.620 1st Qu.: 729.8
## Median : 7406 Median : 5.245 Median :1057.5
## Mean : 7638 Mean : 5.490 Mean : 991.2
## 3rd Qu.:10727 3rd Qu.: 7.713 3rd Qu.:1229.5
## Max. :36019 Max. :28.030 Max. :1440.0
sleepDay_merged %>%
select(TotalSleepRecords,
TotalMinutesAsleep,
TotalTimeInBed) %>%
summary()
## TotalSleepRecords TotalMinutesAsleep TotalTimeInBed
## Min. :1.000 Min. : 58.0 Min. : 61.0
## 1st Qu.:1.000 1st Qu.:361.0 1st Qu.:403.0
## Median :1.000 Median :433.0 Median :463.0
## Mean :1.119 Mean :419.5 Mean :458.6
## 3rd Qu.:1.000 3rd Qu.:490.0 3rd Qu.:526.0
## Max. :3.000 Max. :796.0 Max. :961.0
Merging the two datasets to add columns to one of the datasets that
didnt have before. When doing so like merging
dailyActivity_merged with sleepDay_merged will
create one dataset with both of those datasets put together.
dailyActivity_merged has 33 from the distinct function and
sleepDay_merged has 24 from the distinct function. When the
new merged dataset is merged then you can use n_distinct on
the new dataset it shows 24. Now you can use outerjoin to
keep the ones that were left out. When doing do it will be 33 instead of
24.
combined_data_merged <- merge(dailyActivity_merged, sleepDay_merged,by = "Id", all = TRUE)
n_distinct(combined_data_merged$Id)
## [1] 33
I wanted to know what how long someone slept for and for how long
they stayed in bed, so I created a scatterplot with the new dataset
combined_data. I used TotalMinutesAsleep for
the x-axis and TotalTimeInBed for the y-axis. This chart
shows the user’s sleep data. With this information I can see who slept
the most and the least out of the group.
ggplot(data=combined_data_merged) +
geom_point(mapping = aes(x=TotalMinutesAsleep, y=TotalTimeInBed,
colour = SedentaryMinutes))+
theme(axis.text.x = element_text(angle = -30, vjust = 1, hjust = 0)) +
labs(title = "Bellabeat: Time in Bed vs Total Sleep in Minutes",
subtitle = "Sample of Total Sleep by Smart device users",
caption = "Data collected by Möbius") +
geom_shadowtext(aes(x=300,y=1000),
label = "Total Time spent sleeping",
check_overlap = TRUE,
color="orange",
size=5)
## Warning in geom_shadowtext(aes(x = 300, y = 1000), label = "Total Time spent sleeping", : All aesthetics have length 1, but the data has 12668 rows.
## ℹ Please consider using `annotate()` or provide this layer with data containing
## a single row.
## Warning: Removed 227 rows containing missing values or values outside the scale range
## (`geom_point()`).
Next I created another plot using TotalSteps and
Calories to see how much calories were burned after all of
those steps taken, as well as using SedentaryMinutes for
the color to see how long each person was sitting. This plot shows that
there is one individual that burned the most calories but is not the one
that has the most steps. However, for some reason there is one
individual that has the most steps but he burned half the amount of
calories than the one who burned the most calories. This same person has
the lightest color in the sedentary scale, which states that he spent
most of his time sitting. Either something is wrong with the data but
this is what the data shows.
ggplot(data=combined_data_merged) +
geom_jitter(mapping = aes(x=Calories, y=TotalSteps, color = SedentaryMinutes)) +
theme(axis.text.x = element_text(angle = -30, vjust = 1, hjust = 0)) +
labs(title = "Bellabeat: Total Steps vs Calories",
subtitle = "Total Calories burned by Total Steps",
caption = "Data collected by Möbius") +
geom_shadowtext(aes(x=1500,y=30000),
label = "Total Steps, Calories Burned",
check_overlap = TRUE,
color="orange",
size=5)
## Warning in geom_shadowtext(aes(x = 1500, y = 30000), label = "Total Steps, Calories Burned", : All aesthetics have length 1, but the data has 12668 rows.
## ℹ Please consider using `annotate()` or provide this layer with data containing
## a single row.
This next plot shows TotalSteps vs
TotalDistance and how much Calories burned in
color. The plot looks correct, as it clearly shows the more steps taken
and longer the distance will burn the most Calories. This clearly shows
that the smart device is working properly.
ggplot(data = combined_data_merged) +
geom_jitter(mapping = aes(x = TotalSteps, y = TotalDistance, colour = Calories)) +
theme(axis.text.x = element_text(angle = -30, vjust = 1, hjust = 0)) +
labs(title = "Bellabeat: Total Steps vs Total Distance",
subtitle = "Measuring Distance by Total Steps and Calories Burned",
caption = "Data collected by Möbius") +
geom_shadowtext(aes(x=10000,y=30),
label = "Total Distance Measured by Steps",
check_overlap = TRUE,
color="orange",
size=5)
## Warning in geom_shadowtext(aes(x = 10000, y = 30), label = "Total Distance Measured by Steps", : All aesthetics have length 1, but the data has 12668 rows.
## ℹ Please consider using `annotate()` or provide this layer with data containing
## a single row.
The device works perfectly fine, yes there could be some tweaks or adjustments to make it better. With the three plots shown here, clearly shows that there is a lot of individuals participating but not continuing with their device. Most people did great in the beginning but after a while they stopped. I suggest to implicate an award system.
The smart devices that was used to track the data, shows a lot of useful information. This data shows how many steps they had taken and how long it took them in minutes. As well tracking their sleep, as well as how long they stayed in bed. I used three different plots to showcase which individual did the most and who did the least. However, most of them tended to sit during the duration of the study.
I believe the best Solution would be to implicate an award system, for example, the users have to meet certain criteria like 500 steps and they will get awarded points. These points should be used for discounts on future purchases. This will increase productivity, and also have people more eager and motivated to do more.