Course Project: Shiny Application and Reproducible Pitch

Hayes Chow
Oct 18, 2021

Intro

For more details on authoring R presentations please visit https://support.rstudio.com/hc/en-us/articles/200486468.

library(ggplot2)
library(plotly)
library(curl)

Ingestion / Cleansing / Data Processing

Download files from Reproducible Research Course site https://d396qusza40orc.cloudfront.net/repdata%2Fdata%2Factivity.zip.

url <- "https://d396qusza40orc.cloudfront.net/repdata%2Fdata%2Factivity.zip"
zip <- curl_download(url, "repdata_data_activity.zip")
csv <- unzip(zip, "activity.csv")
df <- read.csv(csv, header = TRUE)

#calc mean interval steps
mean_interval_steps <- aggregate(steps ~ interval, df, mean) 
# merge mean interval steps with data frame to create new data frame
df2 <- merge(df, mean_interval_steps, by = "interval", all.x = TRUE)
# replace NAs with mean interval steps value
df2$steps <- ifelse(is.na(df2$steps.x), df2$steps.y, df2$steps.x)

# create new column for days of the week
df2$days <- weekdays(as.Date(df2$date))
# group days into weekend/weekday
df2$days <- replace(df2$days, df2$days %in% c("Monday", "Tuesday", "Wednesday", 
                                              "Thursday", "Friday"), "weekday")
df2$days <- replace(df2$days, df2$days %in% c("Saturday", "Sunday"), "weekend")

# calc mean for each interval and day
mean_df2a <- aggregate(steps ~ interval + days, df2, mean)
# create a factor variable to order panel plots by weekend/weekday
mean_df2a$days_f <- factor(mean_df2a$days, levels=c("weekend", "weekday"))

Slide With Plot

#histogram
total_df2a <- aggregate(steps ~ date, df2, sum)
  hist(total_df2a$steps, main = "Total number of steps taken each day")

plot of chunk hist_plot

# plot
ggplot(data=mean_df2a,
       aes(x=interval, y=steps, colour=days_f)) +
       geom_line() + ggtitle("Average Daily Steps") + theme(plot.title = element_text(hjust = 0.5))

plot of chunk plot_plot

Thanks!