Load the neccesary packages
library(flexdashboard)
library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr 1.1.3 ✔ readr 2.1.4
## ✔ forcats 1.0.0 ✔ stringr 1.5.0
## ✔ ggplot2 3.4.4 ✔ tibble 3.2.1
## ✔ lubridate 1.9.3 ✔ tidyr 1.3.0
## ✔ purrr 1.0.2
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag() masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(lubridate)
library(patchwork)
options(scipen = 999)
Load all data needed for the plot
trips_summary2 <- read_csv("analysis2.csv", show_col_types = FALSE)
trips_summary3 <- read_csv("analysis3.csv", show_col_types = FALSE)
trips_summary4 <- read_csv("analysis4.csv", show_col_types = FALSE)
Average Duration By Seasons
spring_plot02 <- trips_summary3%>%
filter(yearmonth =="Apr"|yearmonth =="May"|yearmonth =="Jun")%>%
ggplot(aes(x=factor(yearmonth,levels=c('Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec','Jan','Feb','Mar')), y=average_duration, fill=member_casual)) +
geom_col(position = "dodge") +
labs(x = 'yearmonth', title = "Spring")
summer_plot02 <- trips_summary3%>%
filter(yearmonth =="Jul"|yearmonth =="Aug"|yearmonth =="Sep")%>%
ggplot(aes(x=factor(yearmonth,levels=c('Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec','Jan','Feb','Mar')), y=average_duration, fill=member_casual)) +
geom_col(position = "dodge") +
labs(x = 'yearmonth', title = "Summer")
fall_plot02 <- trips_summary3%>%
filter(yearmonth =="Oct"|yearmonth =="Nov"|yearmonth =="Dec")%>%
ggplot(aes(x=factor(yearmonth,levels=c('Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec','Jan','Feb','Mar')), y=average_duration, fill=member_casual)) +
geom_col(position = "dodge") +
labs(x = 'yearmonth', title = "Fall")
winter_plot02 <- trips_summary3%>%
filter(yearmonth =="Jan"|yearmonth =="Feb"|yearmonth =="Mar")%>%
ggplot(aes(x=factor(yearmonth,levels=c('Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec','Jan','Feb','Mar')), y=average_duration, fill=member_casual)) +
geom_col(position = "dodge") +
labs(x = "yearmonth", title = "Winter")
(spring_plot02 | summer_plot02) / (fall_plot02 | winter_plot02)

Number of Rides By Seasons
spring_plot01 <- trips_summary3%>%
filter(yearmonth =="Apr"|yearmonth =="May"|yearmonth =="Jun")%>%
ggplot(aes(x=factor(yearmonth,levels=c('Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec','Jan','Feb','Mar')), y=number_of_rides, fill=member_casual)) +
geom_col(position = "dodge") +
labs(x = "yearmonth", title = "Spring")
summer_plot01 <- trips_summary3%>%
filter(yearmonth =="Jul"|yearmonth =="Aug"|yearmonth =="Sep")%>%
ggplot(aes(x=factor(yearmonth,levels=c('Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec','Jan','Feb','Mar')), y=number_of_rides, fill=member_casual)) +
geom_col(position = "dodge") +
labs(x = "yearmonth", title = "Summer")
fall_plot01 <- trips_summary3%>%
filter(yearmonth =="Oct"|yearmonth =="Nov"|yearmonth =="Dec")%>%
ggplot(aes(x=factor(yearmonth,levels=c('Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec','Jan','Feb','Mar')), y=number_of_rides, fill=member_casual)) +
geom_col(position = "dodge") +
labs(x = "yearmonth", title = "Fall")
winter_plot01 <- trips_summary3%>%
filter(yearmonth =="Jan"|yearmonth =="Feb"|yearmonth =="Mar")%>%
ggplot(aes(x=factor(yearmonth,levels=c('Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec','Jan','Feb','Mar')), y=number_of_rides, fill=member_casual)) +
geom_col(position = "dodge") +
labs(x = "yearmonth", title = "Winter")
(spring_plot01 | summer_plot01) / (fall_plot01 | winter_plot01)

Number of Rides / Average Duration By Rider Type - Weekly
weekly_plot01 <- trips_summary2%>%
ggplot(aes(x=factor(weekday,levels=c('Sun','Mon','Tue','Wed','Thu','Fri','Sat')), y=number_of_rides, fill=member_casual)) +
geom_col(position = "dodge") +
labs( x = "weekday", title = "Weekly Number of Rides")
weekly_plot02 <- trips_summary2%>%
ggplot(aes(x=factor(weekday,levels=c('Sun','Mon','Tue','Wed','Thu','Fri','Sat')), y=average_duration, fill=member_casual)) +
geom_col(position = "dodge") +
labs(x = "weekday", title = "Weekly Average Duration")
weekly_plot01 / weekly_plot02

Number of Rides - Hourly
trips_summary4%>%
ggplot(aes(x=day_hours, y=number_of_rides, fill=member_casual)) +
geom_col(position = "dodge") +
scale_x_continuous(breaks=seq(0,24, by=3)) +
labs(title = "Number of Rides By Rider Type - Hourly",
caption = "24 hour time format")

Number of Rides - Monthly
trips_summary3%>%
ggplot(aes(x=factor(yearmonth,levels=c('Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec','Jan','Feb','Mar')), y=number_of_rides, fill=member_casual)) +
geom_col(position = "dodge") +
theme(axis.text.x=element_text(angle=90,vjust=0.5,hjust=1)) +
labs(x = 'yearmonth', title = "Monthly Number of Rides")

Average Duration - Monthly
trips_summary3%>%
ggplot(aes(x=factor(yearmonth,levels=c('Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec','Jan','Feb','Mar')), y=average_duration, fill=member_casual)) +
geom_col(position = "dodge") +
theme(axis.text.x=element_text(angle=90,vjust=0.5,hjust=1)) +
labs(x = 'yearmonth', title = "Monthly Average Duration")
