install.packages(c(“tidyverse”,“lubridate”,“ggplot2”,“zoo”)) library(tidyverse) library(lubridate) library(ggplot2) library(zoo)
day <- read.csv(“day.csv”)
day\(dteday <- as.Date(day\)dteday, format=“%Y-%m-%d”)
str(day) # Check data structure summary(day) # Summary statistics head(day) # First rows
ggplot(day, aes(x=dteday, y=cnt)) + geom_line(color=“blue”) + labs(title=“Daily Bike Rentals Over Time”, x=“Date”, y=“Count”)
ggplot(day, aes(x=dteday)) + geom_line(aes(y=casual, color=“Casual”)) + geom_line(aes(y=registered, color=“Registered”)) + labs(title=“Casual vs Registered Users”, y=“Count”) + scale_color_manual(values=c(“Casual”=“red”,“Registered”=“green”))
day\(cnt_smooth <- rollmean(day\)cnt, k=7, fill=NA)
ggplot(day, aes(x=dteday)) + geom_line(aes(y=cnt), alpha=0.4) + geom_line(aes(y=cnt_smooth), color=“red”, size=1) + labs(title=“7-Day Rolling Average of Daily Rentals”, y=“Count”)