Hi, I’m Ashley Higgins and this is my first R Markdown project

1. Introduction

This is the capstone project for the Google Data Analytics Course. I will follow the six steps of Data Analysis for the Bellabeat Case Study: Ask, Prepare, Process, Analyze, Share, and Act.

I am a junior data analyst working on the marketing analysis team at Bellabeat, a high-tech manufacturer of health-focused products for women. I have been asked to focus on one of Bellabeat’s products and analyze the user data of a competing product, FitBit, to gain insight on how consumers are using their smart devices. My discoveries and recommendations for marketing strategy will be presented to the Bellabeat executive team. 

About Bellabeat

  • Bellabeat team members:
    • Urška Sršen: Bellabeat’s cofounder and Chief Creative Officer
    • Sando Mur: Mathematician and Bellabeat’s cofounder; key member of the Bellabeat executive team
    • Bellabeat marketing analytics team: A team of data analysts responsible for collecting, analyzing, and reporting data that helps guide Bellabeat’s marketing strategy. I joined this team six months ago and have been busy learning about Bellabeat’s mission and business goals to help Bellabeat achieve them.

  • Bellabeat offers the following products:
    • Bellabeat App: provides users with health data related to their activity, sleep, stress, menstrual cycle, and mindfullness habits. The app connects to the line of smart wellness products, Leaf, Time, and Spring. The data gathered by the app helps users better understand their current habits to make healthy decisions.
    • Leaf: Bellabeat’s classic wellness tracker that can be worn as a bracelet, necklace, or clip. Connects to the app to track activity, sleep, and stress.
    • Time: This wellness watch combines the timeless look of a classic timepiece with smart technology to track user activity, sleep, and stress. Connects with the app to provide insights into daily wellness.
    • Spring: A water bottle that tracks daily water intake using smart technology to ensure that you are appropriately hydrated throughout the day. Connects to the app to track hydration levels.
    • Bellabeat Membership: Subscription-based membership program for users. Gives 24/7 access to fully personalized guidance on nutrition, activity, sleep, health and beauty, and mindfullness based on their lifestyle and goals.

2. Ask

Sršen asked me to analyze smart device usage data in order to gain insight into how consumers use non-Bellabeat smart devices. She then wants me to select one Bellabeat product to apply these insights to in my presentation. 

3. Prepare

The data used for my analysis is public data that explores 33 users of the FitBit tracker (CC0, public domain made available through Mobius)

Set up my environment

install.packages("tidyverse")
library(tidyverse)
library(here)
library(skimr)
library(janitor)
library(lubridate)
library(scales)
library(ggplot2)

Review the Data

We’ll be focusing on 30 days of data from 7 files during the dates April 12, 2016 to May 12, 2016.

Import the data

daily_activity <- read.csv("mturkfitbit_export_4.12.16-5.12.16/Fitabase Data 4.12.16-5.12.16/dailyActivity_merged.csv", header = TRUE)
daily_steps <- read.csv("mturkfitbit_export_4.12.16-5.12.16/Fitabase Data 4.12.16-5.12.16/dailySteps_merged.csv", header = TRUE)
daily_sleep <- read.csv("mturkfitbit_export_4.12.16-5.12.16/Fitabase Data 4.12.16-5.12.16/sleepDay_merged.csv", header = TRUE)
hourly_steps <- read.csv("mturkfitbit_export_4.12.16-5.12.16/Fitabase Data 4.12.16-5.12.16/hourlySteps_merged.csv", header = TRUE)
hourly_calories <- read.csv("mturkfitbit_export_4.12.16-5.12.16/Fitabase Data 4.12.16-5.12.16/hourlyCalories_merged.csv", header = TRUE)
hourly_intensities <- read.csv("mturkfitbit_export_4.12.16-5.12.16/Fitabase Data 4.12.16-5.12.16/hourlyIntensities_merged.csv", header = TRUE)
weight <- read.csv("mturkfitbit_export_4.12.16-5.12.16/Fitabase Data 4.12.16-5.12.16/weightLogInfo_merged.csv", header = TRUE)

Preview the data

head(daily_activity)
##           Id ActivityDate TotalSteps TotalDistance TrackerDistance
## 1 1503960366    4/12/2016      13162          8.50            8.50
## 2 1503960366    4/13/2016      10735          6.97            6.97
## 3 1503960366    4/14/2016      10460          6.74            6.74
## 4 1503960366    4/15/2016       9762          6.28            6.28
## 5 1503960366    4/16/2016      12669          8.16            8.16
## 6 1503960366    4/17/2016       9705          6.48            6.48
##   LoggedActivitiesDistance VeryActiveDistance ModeratelyActiveDistance
## 1                        0               1.88                     0.55
## 2                        0               1.57                     0.69
## 3                        0               2.44                     0.40
## 4                        0               2.14                     1.26
## 5                        0               2.71                     0.41
## 6                        0               3.19                     0.78
##   LightActiveDistance SedentaryActiveDistance VeryActiveMinutes
## 1                6.06                       0                25
## 2                4.71                       0                21
## 3                3.91                       0                30
## 4                2.83                       0                29
## 5                5.04                       0                36
## 6                2.51                       0                38
##   FairlyActiveMinutes LightlyActiveMinutes SedentaryMinutes Calories
## 1                  13                  328              728     1985
## 2                  19                  217              776     1797
## 3                  11                  181             1218     1776
## 4                  34                  209              726     1745
## 5                  10                  221              773     1863
## 6                  20                  164              539     1728
head(daily_sleep)
##           Id              SleepDay TotalSleepRecords TotalMinutesAsleep
## 1 1503960366 4/12/2016 12:00:00 AM                 1                327
## 2 1503960366 4/13/2016 12:00:00 AM                 2                384
## 3 1503960366 4/15/2016 12:00:00 AM                 1                412
## 4 1503960366 4/16/2016 12:00:00 AM                 2                340
## 5 1503960366 4/17/2016 12:00:00 AM                 1                700
## 6 1503960366 4/19/2016 12:00:00 AM                 1                304
##   TotalTimeInBed
## 1            346
## 2            407
## 3            442
## 4            367
## 5            712
## 6            320
head(daily_steps)
##           Id ActivityDay StepTotal
## 1 1503960366   4/12/2016     13162
## 2 1503960366   4/13/2016     10735
## 3 1503960366   4/14/2016     10460
## 4 1503960366   4/15/2016      9762
## 5 1503960366   4/16/2016     12669
## 6 1503960366   4/17/2016      9705
head(hourly_calories)
##           Id          ActivityHour Calories
## 1 1503960366 4/12/2016 12:00:00 AM       81
## 2 1503960366  4/12/2016 1:00:00 AM       61
## 3 1503960366  4/12/2016 2:00:00 AM       59
## 4 1503960366  4/12/2016 3:00:00 AM       47
## 5 1503960366  4/12/2016 4:00:00 AM       48
## 6 1503960366  4/12/2016 5:00:00 AM       48
head(hourly_intensities)
##           Id          ActivityHour TotalIntensity AverageIntensity
## 1 1503960366 4/12/2016 12:00:00 AM             20         0.333333
## 2 1503960366  4/12/2016 1:00:00 AM              8         0.133333
## 3 1503960366  4/12/2016 2:00:00 AM              7         0.116667
## 4 1503960366  4/12/2016 3:00:00 AM              0         0.000000
## 5 1503960366  4/12/2016 4:00:00 AM              0         0.000000
## 6 1503960366  4/12/2016 5:00:00 AM              0         0.000000
head(hourly_steps)
##           Id          ActivityHour StepTotal
## 1 1503960366 4/12/2016 12:00:00 AM       373
## 2 1503960366  4/12/2016 1:00:00 AM       160
## 3 1503960366  4/12/2016 2:00:00 AM       151
## 4 1503960366  4/12/2016 3:00:00 AM         0
## 5 1503960366  4/12/2016 4:00:00 AM         0
## 6 1503960366  4/12/2016 5:00:00 AM         0
head(weight)
##           Id                  Date WeightKg WeightPounds Fat   BMI
## 1 1503960366  5/2/2016 11:59:59 PM     52.6     115.9631  22 22.65
## 2 1503960366  5/3/2016 11:59:59 PM     52.6     115.9631  NA 22.65
## 3 1927972279  4/13/2016 1:08:52 AM    133.5     294.3171  NA 47.54
## 4 2873212765 4/21/2016 11:59:59 PM     56.7     125.0021  NA 21.45
## 5 2873212765 5/12/2016 11:59:59 PM     57.3     126.3249  NA 21.69
## 6 4319703577 4/17/2016 11:59:59 PM     72.4     159.6147  25 27.45
##   IsManualReport        LogId
## 1           True 1.462234e+12
## 2           True 1.462320e+12
## 3          False 1.460510e+12
## 4           True 1.461283e+12
## 5           True 1.463098e+12
## 6           True 1.460938e+12
str(daily_activity)
## 'data.frame':    940 obs. of  15 variables:
##  $ Id                      : num  1.5e+09 1.5e+09 1.5e+09 1.5e+09 1.5e+09 ...
##  $ ActivityDate            : chr  "4/12/2016" "4/13/2016" "4/14/2016" "4/15/2016" ...
##  $ TotalSteps              : int  13162 10735 10460 9762 12669 9705 13019 15506 10544 9819 ...
##  $ TotalDistance           : num  8.5 6.97 6.74 6.28 8.16 ...
##  $ TrackerDistance         : num  8.5 6.97 6.74 6.28 8.16 ...
##  $ LoggedActivitiesDistance: num  0 0 0 0 0 0 0 0 0 0 ...
##  $ VeryActiveDistance      : num  1.88 1.57 2.44 2.14 2.71 ...
##  $ ModeratelyActiveDistance: num  0.55 0.69 0.4 1.26 0.41 ...
##  $ LightActiveDistance     : num  6.06 4.71 3.91 2.83 5.04 ...
##  $ SedentaryActiveDistance : num  0 0 0 0 0 0 0 0 0 0 ...
##  $ VeryActiveMinutes       : int  25 21 30 29 36 38 42 50 28 19 ...
##  $ FairlyActiveMinutes     : int  13 19 11 34 10 20 16 31 12 8 ...
##  $ LightlyActiveMinutes    : int  328 217 181 209 221 164 233 264 205 211 ...
##  $ SedentaryMinutes        : int  728 776 1218 726 773 539 1149 775 818 838 ...
##  $ Calories                : int  1985 1797 1776 1745 1863 1728 1921 2035 1786 1775 ...
str(daily_sleep)
## 'data.frame':    413 obs. of  5 variables:
##  $ Id                : num  1.5e+09 1.5e+09 1.5e+09 1.5e+09 1.5e+09 ...
##  $ SleepDay          : chr  "4/12/2016 12:00:00 AM" "4/13/2016 12:00:00 AM" "4/15/2016 12:00:00 AM" "4/16/2016 12:00:00 AM" ...
##  $ TotalSleepRecords : int  1 2 1 2 1 1 1 1 1 1 ...
##  $ TotalMinutesAsleep: int  327 384 412 340 700 304 360 325 361 430 ...
##  $ TotalTimeInBed    : int  346 407 442 367 712 320 377 364 384 449 ...
str(daily_steps)
## 'data.frame':    940 obs. of  3 variables:
##  $ Id         : num  1.5e+09 1.5e+09 1.5e+09 1.5e+09 1.5e+09 ...
##  $ ActivityDay: chr  "4/12/2016" "4/13/2016" "4/14/2016" "4/15/2016" ...
##  $ StepTotal  : int  13162 10735 10460 9762 12669 9705 13019 15506 10544 9819 ...
str(hourly_calories)
## 'data.frame':    22099 obs. of  3 variables:
##  $ Id          : num  1.5e+09 1.5e+09 1.5e+09 1.5e+09 1.5e+09 ...
##  $ ActivityHour: chr  "4/12/2016 12:00:00 AM" "4/12/2016 1:00:00 AM" "4/12/2016 2:00:00 AM" "4/12/2016 3:00:00 AM" ...
##  $ Calories    : int  81 61 59 47 48 48 48 47 68 141 ...
str(hourly_intensities)
## 'data.frame':    22099 obs. of  4 variables:
##  $ Id              : num  1.5e+09 1.5e+09 1.5e+09 1.5e+09 1.5e+09 ...
##  $ ActivityHour    : chr  "4/12/2016 12:00:00 AM" "4/12/2016 1:00:00 AM" "4/12/2016 2:00:00 AM" "4/12/2016 3:00:00 AM" ...
##  $ TotalIntensity  : int  20 8 7 0 0 0 0 0 13 30 ...
##  $ AverageIntensity: num  0.333 0.133 0.117 0 0 ...
str(hourly_steps)
## 'data.frame':    22099 obs. of  3 variables:
##  $ Id          : num  1.5e+09 1.5e+09 1.5e+09 1.5e+09 1.5e+09 ...
##  $ ActivityHour: chr  "4/12/2016 12:00:00 AM" "4/12/2016 1:00:00 AM" "4/12/2016 2:00:00 AM" "4/12/2016 3:00:00 AM" ...
##  $ StepTotal   : int  373 160 151 0 0 0 0 0 250 1864 ...
str(weight)
## 'data.frame':    67 obs. of  8 variables:
##  $ Id            : num  1.50e+09 1.50e+09 1.93e+09 2.87e+09 2.87e+09 ...
##  $ Date          : chr  "5/2/2016 11:59:59 PM" "5/3/2016 11:59:59 PM" "4/13/2016 1:08:52 AM" "4/21/2016 11:59:59 PM" ...
##  $ WeightKg      : num  52.6 52.6 133.5 56.7 57.3 ...
##  $ WeightPounds  : num  116 116 294 125 126 ...
##  $ Fat           : int  22 NA NA NA NA 25 NA NA NA NA ...
##  $ BMI           : num  22.6 22.6 47.5 21.5 21.7 ...
##  $ IsManualReport: chr  "True" "True" "False" "True" ...
##  $ LogId         : num  1.46e+12 1.46e+12 1.46e+12 1.46e+12 1.46e+12 ...

Check the unique number of users in each dataframe

n_unique(daily_activity$Id)
## [1] 33
n_unique(daily_sleep$Id)
## [1] 24
n_unique(daily_steps$Id)
## [1] 33
n_unique(hourly_calories$Id)
## [1] 33
n_unique(hourly_intensities$Id)
## [1] 33
n_unique(hourly_steps$Id)
## [1] 33
n_unique(weight$Id)
## [1] 8

All data sets have 33 participants each except the daily_sleep and weight data set which has 24 and 8 participants respectively.

I will drop the weight data set because 8 participants is too small a sample to draw conclusions and make recommendations.

Check for duplicates in data

sum(duplicated(daily_activity))
## [1] 0
sum(duplicated(daily_sleep))
## [1] 3
sum(duplicated(daily_steps))
## [1] 0
sum(duplicated(hourly_calories))
## [1] 0
sum(duplicated(hourly_intensities))
## [1] 0
sum(duplicated(hourly_steps))
## [1] 0

4. Clean the data

Starting with daily_activity dataframe

Remove all duplicates and missing data from all dataframes

daily_activity <- daily_activity %>%
  distinct() %>%
  drop_na()
daily_sleep <- daily_sleep %>%
  distinct() %>%
  drop_na()
daily_steps <- daily_steps %>%
  distinct() %>%
  drop_na()
hourly_calories <- hourly_calories %>%
  distinct() %>%
  drop_na()
hourly_intensities <- hourly_intensities %>%
  distinct() %>%
  drop_na()
hourly_steps <- hourly_steps %>%
  distinct() %>%
  drop_na()

Clean and rename columns of all dataframes

I will clean date-time format for daily_activity and daily_sleep since they are the wrong data type and both dataframes will be merged. I will not be using the time from daily_sleep.

For our hourly_calories, hourly_intensities and hourly_steps dataset, I will convert date string to date-time.

daily_activity <- daily_activity %>%
  rename(date = activitydate) %>%
  mutate(date = as_date(date, format = "%m/%d/%Y"))
daily_sleep <- daily_sleep %>%
  rename(date = sleepday) %>%
  mutate(date = as_date(date, format = "%m/%d/%Y %I:%M:%S %p", tz = Sys.timezone()))
hourly_calories <- hourly_calories %>% 
  rename(date_time = activityhour) %>% 
  mutate(date_time = as.POSIXct(date_time, format = "%m/%d/%Y %I:%M:%S %p" , tz = Sys.timezone()))
hourly_intensities <- hourly_intensities %>% 
  rename(date_time = activityhour) %>% 
  mutate(date_time = as.POSIXct(date_time, format = "%m/%d/%Y %I:%M:%S %p" , tz = Sys.timezone()))
hourly_steps<- hourly_steps %>% 
  rename(date_time = activityhour) %>% 
  mutate(date_time = as.POSIXct(date_time, format = "%m/%d/%Y %I:%M:%S %p" , tz = Sys.timezone()))

Merge the daily_activity and daily_sleep data sets together.

daily_activity_sleep <- merge(daily_activity, daily_sleep, by=c ("id", "date"))
view(daily_activity_sleep)

Summarize and Explore daily activity

daily_activity %>%  
  select(totalsteps,
         totaldistance,
         sedentaryminutes, calories) %>%
  summary()
##    totalsteps    totaldistance    sedentaryminutes    calories   
##  Min.   :    0   Min.   : 0.000   Min.   :   0.0   Min.   :   0  
##  1st Qu.: 3790   1st Qu.: 2.620   1st Qu.: 729.8   1st Qu.:1828  
##  Median : 7406   Median : 5.245   Median :1057.5   Median :2134  
##  Mean   : 7638   Mean   : 5.490   Mean   : 991.2   Mean   :2304  
##  3rd Qu.:10727   3rd Qu.: 7.713   3rd Qu.:1229.5   3rd Qu.:2793  
##  Max.   :36019   Max.   :28.030   Max.   :1440.0   Max.   :4900

4. Analyze

Create chart for number of activities per day

daily_activity %>% count(date, sort = TRUE) %>% 
  ggplot() + geom_col(aes(x = date, y = n), color = "black", fill = "white") + 
  scale_y_continuous() + 
  scale_x_date(date_breaks = "1 day") + 
  theme(axis.text.x = element_text(angle = 90, vjust = 0.5, hjust = 1)) + 
  labs(title = "Count of Activities Per Day By All Users", x = "Activity Date", y = "Number of Activities")

Steps Per day plot

total_steps <- daily_activity %>% group_by(date) %>% 
  summarize(Steps = sum(totalsteps), Mean = mean(totalsteps, na.rm = TRUE))
  ggplot(total_steps) + geom_step(aes(x = date, y = Steps), color = "darkgreen") +
  scale_x_date(date_breaks = "1 day") + 
  theme(axis.text.x = element_text(angle = 90, vjust = 0.5, hjust = 1)) + 
  labs(title = "Total Steps Per Day By All Users", x = "Activity Date", y = "Number of Steps") + 
  scale_y_continuous(labels = comma)

Avg Steps Per Day

ggplot(total_steps) + geom_step(aes(x = date, y = Mean), color = "green") +
    scale_x_date(date_breaks = "1 day") + 
    theme(axis.text.x = element_text(angle = 90, vjust = 0.5, hjust = 1)) + 
    labs(title = "Average Steps Per Day", x = "Activity Date", y = "Number of Steps") + 
    scale_y_continuous(labels = comma)

Total Distance Plot

total_distance <- daily_activity %>% group_by(date) %>% 
  summarise(Total = sum(totaldistance, na.rm = TRUE), Mean = mean(totaldistance, na.rm = TRUE))
ggplot(total_distance) +
  geom_step(aes(x = date, y = Total), color = "red") +
  scale_x_date(date_breaks = "1 day") + 
  theme(axis.text.x = element_text(angle = 90, vjust = 0.5, hjust = 1)) + 
  labs(title = "Average Distance Per Day", x = "Activity Date", y = "Distance")

Average Distance Plot

ggplot(total_distance) +
  geom_step(aes(x = date, y = Mean), color = "hotpink") +
  scale_x_date(date_breaks = "1 day") + 
  theme(axis.text.x = element_text(angle = 90, vjust = 0.5, hjust = 1)) + 
  labs(title = "Average Distance Per Day", x = "Activity Date", y = "Distance")

Hourly Steps through the day Separate the datetime column into date and time column

hourly_steps <- hourly_steps %>%
  separate(date_time, into = c("date", "time"), sep= " ") %>%
  mutate(date = ymd(date)) 
## Warning: Expected 2 pieces. Missing pieces filled with `NA` in 934 rows [1, 25, 49, 73,
## 97, 121, 145, 169, 193, 217, 241, 265, 289, 313, 337, 361, 385, 409, 433, 457,
## ...].
head(hourly_steps)
##           id       date     time steptotal
## 1 1503960366 2016-04-12     <NA>       373
## 2 1503960366 2016-04-12 01:00:00       160
## 3 1503960366 2016-04-12 02:00:00       151
## 4 1503960366 2016-04-12 03:00:00         0
## 5 1503960366 2016-04-12 04:00:00         0
## 6 1503960366 2016-04-12 05:00:00         0
hourly_steps %>%
  group_by(time) %>%
  summarize(average_steps = mean(steptotal)) %>%
  ggplot() +
  geom_col(mapping = aes(x=time, y = average_steps, fill = average_steps)) + 
  labs(title = "Hourly steps throughout the day", x="Time of Day", y="Number of Steps") + 
  scale_fill_gradient(low = "orange", high = "purple")+
  theme(axis.text.x = element_text(angle = 90))

Calories vs Steps

ggplot(data = daily_activity, aes(x = totalsteps, y = calories)) + 
  geom_point() + 
  geom_smooth() + 
  labs(title ="Total Steps vs. Calories By All Users")
## `geom_smooth()` using method = 'loess' and formula = 'y ~ x'

To know what day of the week users are more active.

weekday_steps <- daily_activity %>%
  mutate(weekday = weekdays(date))
weekday_steps$weekday <- ordered(weekday_steps$weekday, levels=c("Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"))
weekday_steps <-weekday_steps %>%
  group_by(weekday) %>%
  summarize (daily_steps = mean(totalsteps))

head(weekday_steps)
## # A tibble: 6 × 2
##   weekday   daily_steps
##   <ord>           <dbl>
## 1 Monday          7781.
## 2 Tuesday         8125.
## 3 Wednesday       7559.
## 4 Thursday        7406.
## 5 Friday          7448.
## 6 Saturday        8153.
ggplot(weekday_steps, aes(weekday, daily_steps)) +
  geom_col(fill = "purple") +
  geom_hline(yintercept = 7500, color ="red") +
  labs(title = "Average Daily Steps By Weekday", x= "", y = "") +
  theme(axis.text.x = element_text(angle = 45,vjust = 0.5, hjust = 1)) +
  annotate("text", x = 4, y = 8500, label = "Recommended Amount of Steps Daily is 7500", color = "red")

Summarize and Explore sleep

daily_activity_sleep %>%  
  select(totalminutesasleep,
         totaltimeinbed) %>%
  summary()
##  totalminutesasleep totaltimeinbed 
##  Min.   : 58.0      Min.   : 61.0  
##  1st Qu.:361.0      1st Qu.:403.8  
##  Median :432.5      Median :463.0  
##  Mean   :419.2      Mean   :458.5  
##  3rd Qu.:490.0      3rd Qu.:526.0  
##  Max.   :796.0      Max.   :961.0

To know what day of the week users sleep the most

weekday_sleep <- daily_sleep %>%
  mutate(weekday = weekdays(date))
weekday_sleep$weekday <- ordered(weekday_sleep$weekday, levels = c("Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"))

weekday_sleep <-weekday_sleep %>%
  group_by(weekday) %>%
  summarize(daily_sleep = mean(totalminutesasleep/60))

head(weekday_sleep)
## # A tibble: 6 × 2
##   weekday   daily_sleep
##   <ord>           <dbl>
## 1 Monday           6.99
## 2 Tuesday          6.74
## 3 Wednesday        7.24
## 4 Thursday         6.69
## 5 Friday           6.76
## 6 Saturday         6.98
ggplot(weekday_sleep, aes(weekday, daily_sleep)) +
  geom_col(fill = "skyblue") +
  geom_hline(yintercept = 8, color = "darkblue") +
  labs(title = "Average Hours Asleep By Day", x= "", y = "Hours") +
  theme(axis.text.x = element_text(angle = 45,vjust = 0.5, hjust = 1)) +
  annotate("text", x = 2, y = 7.5, label = "Recommended Amount of Sleep is 8 Hours", color = "darkblue")

Summarize and Explore hourly intensities throughout the day

First, split the datetime column into date and time columns

hourly_intensities <- hourly_intensities %>%
  separate(date_time, into = c("date", "time"), sep= " ") 
## Warning: Expected 2 pieces. Missing pieces filled with `NA` in 934 rows [1, 25, 49, 73,
## 97, 121, 145, 169, 193, 217, 241, 265, 289, 313, 337, 361, 385, 409, 433, 457,
## ...].
head(hourly_intensities)
##           id       date     time totalintensity averageintensity
## 1 1503960366 2016-04-12     <NA>             20         0.333333
## 2 1503960366 2016-04-12 01:00:00              8         0.133333
## 3 1503960366 2016-04-12 02:00:00              7         0.116667
## 4 1503960366 2016-04-12 03:00:00              0         0.000000
## 5 1503960366 2016-04-12 04:00:00              0         0.000000
## 6 1503960366 2016-04-12 05:00:00              0         0.000000
hourly_intensities <- hourly_intensities %>%
  group_by(time) %>%
  drop_na() %>%
  summarize(mean_total_int = mean(totalintensity))
ggplot(data = hourly_intensities, aes(x = time, y = mean_total_int)) + 
  geom_histogram(stat = "identity", fill = "orange") +
  theme(axis.text.x = element_text(angle = 90)) +
  labs(title = "Average Total Intensity vs. Time", x = "Time of Day", y = "Average Intensity")
## Warning in geom_histogram(stat = "identity", fill = "orange"): Ignoring unknown
## parameters: `binwidth`, `bins`, and `pad`

### User Information

daily_use <- daily_activity_sleep %>%
  group_by(id) %>%
  summarize(days_used=sum(n())) %>%
  mutate(user_type= case_when(
    days_used >= 1 & days_used <= 10 ~ "low user",
    days_used >= 11 & days_used <= 20 ~ "moderate user", 
    days_used >= 21 & days_used <= 31 ~ "high user", 
    ))

head(daily_use)
## # A tibble: 6 × 3
##           id days_used user_type
##        <dbl>     <int> <chr>    
## 1 1503960366        25 high user
## 2 1644430081         4 low user 
## 3 1844505072         3 low user 
## 4 1927972279         5 low user 
## 5 2026352035        28 high user
## 6 2320127002         1 low user
daily_use_percent <- daily_use %>%
  group_by(user_type) %>%
  summarize(total = n()) %>%
  mutate(totals = sum(total)) %>%
  group_by(user_type) %>%
  summarise(total_percent = total / totals) %>%
  mutate(labels = scales::percent(total_percent))

daily_use_percent$user_type <- factor(daily_use_percent$user_type, levels = c("high user", "moderate user", "low user"))

head(daily_use_percent)
## # A tibble: 3 × 3
##   user_type     total_percent labels
##   <fct>                 <dbl> <chr> 
## 1 high user             0.5   50%   
## 2 low user              0.375 38%   
## 3 moderate user         0.125 12%
daily_use_percent %>%
  ggplot(aes(x = "",y = total_percent, fill = user_type)) +
  geom_bar(stat = "identity", width = 1)+
  coord_polar("y", start=0)+
  theme_minimal()+
  theme(axis.title.x= element_blank(),
        axis.title.y = element_blank(),
        panel.border = element_blank(), 
        panel.grid = element_blank(), 
        axis.ticks = element_blank(),
        axis.text.x = element_blank(),
        plot.title = element_text(hjust = 0.5, size=14, face = "bold")) +
  geom_text(aes(label = labels),
            position = position_stack(vjust = 0.5))+
  scale_fill_manual(values = c( "lightgreen","yellow","red"),
                    labels = c("High user - 21 to 31 days",
                               "Moderate user - 11 to 20 days",
                               "Low user - 1 to 10 days"))+
  labs(title="Daily use of smart device")