Sorting data

bikedata$weekdays<- wday(strptime(bikedata$Start.Date,format="%d/%m/%Y %H:%M",
                                  tz="UTC"),label = T)


##################day time function
daytime<- function(data4=bikedata){
  a<- strptime(data4$Start.Date,format="%d/%m/%Y %R",tz="UTC")
  b<- format(a, "%R")
  Time <- hour(hm(b))
  timeofday <- hour(hm("00:00", "6:00", "12:00", "18:00", "23:59"))
  names <- c("Night", "Morning", "Afternoon", "Evening")
  z<-cut(x=Time, breaks=timeofday, labels=names, include.lowest=TRUE)
  return(z)
}
#######################################################season 
Season <- function(data2) {
  d<- as.Date(strptime(data2$Start.Date,format="%d/%m/%Y %H:%M",tz="UTC"))
  WS <- as.Date("21/12/2017", format = "%d/%m/%Y") # Winter 
  SE <- as.Date("20/3/2017",  format = "%d/%m/%Y") # Spring 
  SS <- as.Date("21/6/2017",  format = "%d/%m/%Y") # Summer 
  FE <- as.Date("22/9/2017",  format = "%d/%m/%Y") # Autumn
  
  ifelse (d >= WS | d < SE, "Winter",
          ifelse (d >= SE & d < SS, "Spring",
                  ifelse (d >= SS & d < FE, "Summer", "Autumn")))
}
bikedata$season<-as.factor(Season(data2=bikedata))
bikedata$Daytime<- daytime(data4=bikedata)
bikedata$Start.Date<- as.Date(strptime(bikedata$Start.Date,
                                              format="%d/%m/%Y %H:%M",tz="UTC"))

bikedata$weekdays<- factor(bikedata$weekdays,ordered = FALSE)
x<-(plyr::count(bikedata$Start.Date))
colnames(x)<- c("Start.Date","ntrips")
bikedata<-join(x,bikedata)
## Joining by: Start.Date
bikedata<- bikedata%>% dplyr::select("ntrips","weekdays","season","Daytime","Duration")
bikedata<- na.omit(bikedata)
str(bikedata)
## 'data.frame':    8434530 obs. of  5 variables:
##  $ ntrips  : int  21955 21955 21955 21955 21955 21955 21955 21955 21955 21955 ...
##  $ weekdays: Factor w/ 7 levels "Sun","Mon","Tues",..: 4 4 4 4 4 4 4 4 4 4 ...
##  $ season  : Factor w/ 4 levels "Autumn","Spring",..: 4 4 4 4 4 4 4 4 4 4 ...
##  $ Daytime : Factor w/ 4 levels "Night","Morning",..: 3 2 3 3 3 3 2 3 4 3 ...
##  $ Duration: int  660 600 540 180 300 900 420 600 660 420 ...

Exploratory analysis

###################weekdays and season
ggplot(data=bikedata,aes(x=weekdays,y=ntrips))+
  geom_boxplot(aes(fill=season))+facet_grid(~season)+
   ggtitle("Boxplot of the number of trips by weekdays and season")+
  theme(plot.title = element_text(hjust = 0.5))+
  theme(axis.text.x = element_text(angle = 45, hjust = 1))

Relatively speaking, colder seasons have fewer number of trips. Weekdays are more popular for the cyclest than weekends especially in autumn and winter seasons, however the number of trips among weekdays seems to be constant during summer or spring.

##############weekdays and daytime
ggplot(data=bikedata,aes(x=weekdays,y=ntrips))+
  geom_boxplot(aes(fill=Daytime))+facet_grid(~Daytime)+
  ggtitle("Boxplot of the number of trips by weekdays and daytime")+
  theme(plot.title = element_text(hjust = 0.5))+
  theme(axis.text.x = element_text(angle = 45, hjust = 1))

The number of trips seems to be similar amidst different Daytime and weekdays. (one thing that worth to metion is that in Sunday evening, there are many data below the lower qutial range, however the mean remain unaffected).

#########Season and daytime
ggplot(data=bikedata,aes(x=season,y=ntrips))+
  geom_boxplot(aes(fill=Daytime))+facet_grid(~Daytime)+
  ggtitle("Boxplot of the number of trips by season and daytime")+
  theme(plot.title = element_text(hjust = 0.5))+
  theme(axis.text.x = element_text(angle = 45, hjust = 1))

A stright forward seasonal pattern we can spot here. An increasing number of trips by changing the seasons from colder to warmer. seasonal change does not influence the daytime.