Skip to content

Instantly share code, notes, and snippets.

View akshat3096's full-sized avatar

Akshat arora akshat3096

View GitHub Profile
install.packages("lubridate")
library(lubridate)
#make endDate in a date-time variable POSIXct using lubridate with Indian time zone
df$endDate <-ymd_hms(df$endDate,tz="UTC")
#new features 
df$month<-format(df$endDate,"%m")
df$year<-format(df$endDate,"%Y")
install.packages("XML")
library(XML)
xml <- xmlParse("export.xml")
summary(xml)
#convert the XML object to data frame
df <- XML:::xmlAttrsToDataFrame(xml["//Record"])
heart_rate <- df %>%
filter(type == 'HKQuantityTypeIdentifierHeartRate') %>%
group_by(date,year,month) %>%
summarize(heart_rate=mean(value))
p1 <- ggplot(heart_rate,aes(x=date, y=heart_rate, group=year)) +
geom_line(aes(colour=year))+
ggtitle("Mean heartrate over the months")
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))+
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)+
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")
str(df)
table(df$type)
install.packages("tidyverse")
install.packages("ggplot2")
library(tidyverse)
library(ggplot2)