Skip to content

Instantly share code, notes, and snippets.

View akshat3096's full-sized avatar

Akshat arora akshat3096

View GitHub Profile
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")
# 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)) +
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")
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")
plot+
geom_point() +
transition_reveal(as.numeric(month))
install.packages("gganimate")
library(gganimate)
#animating the above plot
p1+transition_reveal(as.numeric(date))
#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")
install.packages("tidyverse")
install.packages("ggplot2")
library(tidyverse)
library(ggplot2)
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)+
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))+