This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
flight<-df %>% | |
filter(type == 'HKQuantityTypeIdentifierFlightsClimbed') %>% | |
group_by(year,month) %>% | |
summarize(flights=sum(value)) %>% | |
print (n=100) %>% | |
ggplot(aes(x=month, y=flights, fill=year)) + | |
geom_bar(position='dodge', stat='identity') + | |
scale_y_continuous(labels = scales::comma) + | |
theme(panel.grid.major = element_blank())+ | |
ggtitle("Total flights climbed") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# calendar heatmap: year wise calories burned | |
f <- df %>% | |
filter(type == 'HKQuantityTypeIdentifierActiveEnergyBurned') %>% | |
filter(year==2018) %>% | |
mutate(week_date = ceiling(day(creationDate) / 7)) %>% | |
group_by(week_date, month, dayofweek) %>% | |
summarise(total_cal = sum(value)) | |
p <- ggplot(f, | |
aes(dayofweek, week_date, fill = f$total_cal)) + |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
energy <- df %>% | |
filter(type == 'HKQuantityTypeIdentifierActiveEnergyBurned') %>% | |
group_by(date,year,month) %>% | |
summarize(energy_burned=sum(value)) | |
energy$date <- as.Date(energy$date,"%Y-%m-%d") | |
plot3 <- ggplot(energy,aes(x=date, y=energy_burned, group=year)) + | |
geom_line(aes(colour=year))+ | |
ggtitle("Total Energy burned") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
step_count <- df %>% | |
filter(type == 'HKQuantityTypeIdentifierStepCount') %>% | |
filter(year==2019) %>% | |
group_by(dayofweek,year,month) %>% | |
summarize(step_count=median(value)) | |
plot <- ggplot(step_count,aes(x=month, y=step_count, group=dayofweek)) + | |
geom_line(aes(colour=dayofweek),size=1.5)+ | |
theme_minimal()+ | |
ggtitle("Weekly median stepcount") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
plot+ | |
geom_point() + | |
transition_reveal(as.numeric(month)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
install.packages("gganimate") | |
library(gganimate) | |
#animating the above plot | |
p1+transition_reveal(as.numeric(date)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#convert the date format first | |
heart_rate$date <- as.Date(heart_rate$date,"%Y-%m-%d") | |
p1 <- p1+scale_x_date(date_labels = "%b/%Y") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
install.packages("tidyverse") | |
install.packages("ggplot2") | |
library(tidyverse) | |
library(ggplot2) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
steps <- df %>% | |
filter(type == 'HKQuantityTypeIdentifierStepCount') %>% | |
group_by(date,year,month) %>% | |
summarize(steps=sum(value)) | |
steps$date <- as.Date(steps$date,"%Y-%m-%d") | |
plot2 <- ggplot(steps,aes(x=date, y=steps, group=year)) + | |
geom_line(aes(colour=year))+ | |
geom_snooth(se=F)+ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
heart_rate <- df %>% | |
filter(type == 'HKQuantityTypeIdentifierHeartRate') %>% | |
group_by(date,year,month) %>% | |
summarize(heart_rate=median(value))+ | |
xlab("Month/Year") | |
heart_rate$date <- as.Date(heart_rate$date,"%Y-%m-%d") | |
plot <- ggplot(heart_rate,aes(x=date, y=heart_rate, group=year)) + | |
geom_line(aes(colour=year))+ |