by Roman Baishev
Cyclistic is a bike-share company in Chicago.
Cyclistic has a successful bike-share offering program comprising 5,824 bicycles that are geotracked and locked into a network of 692 stations.
Pricing plans allow the flexibility of purchasing single-ride passes, full-day passes or Cyclistic memberships. Customers who purchase single-ride or full-day passes are referred to as casual riders. Customers who purchase Cyclistic membership are Cyclistic members.
Cyclistic users are more likely to ride for leisure but about 30% use bikes to commute to work every day.
Lily Moreno, the director of marketing in Cyclistic, has set a clear goal: design marketing strategies aimed at converting casual riders into annual members.
I was assigned the question to answer: How do annual members and casual riders use Cyclistic bikes differently?
I am to identify, interpret and visualize these differences and help the marketing team to answer the next question: Why would casual riders buy Cyclistic annual membership?
To analyze and identify trends, used Cyclistic’s historical trip data provided by the company, downloaded here.
The ‘Cyclistic’ data has been made available by Motivate International Inc. under this license.
As an auxiliary data set, I used Jersey City data from Citi Bike Trip Histories. This data was provided according to the NYCBS Data Use Policy.
Both data sets cover 12 months of riding from February 2023 to January 2024.
Both sets are:
reliable, because they originate from the sources I can trust;
comprehensive, because they have sufficient information to identify and distinguish riding patterns of casual clients and club members;
original, as they are provided by bicycle share services, who gathered the data .
definitely current,
cited.
Therefore, this data ROCCCS.
knitr::opts_chunk$set(warning = FALSE, message = FALSE)
library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr 1.1.4 ✔ readr 2.1.5
## ✔ forcats 1.0.0 ✔ stringr 1.5.1
## ✔ ggplot2 3.4.4 ✔ tibble 3.2.1
## ✔ lubridate 1.9.3 ✔ tidyr 1.3.1
## ✔ 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(readr)
library(forcats)
library(forcats)
library(ggrepel)
#library(ggpubr)
library(REdaS)
## Загрузка требуемого пакета: grid
library(leaflet)
library(htmltools)
Handled the main data set received from ‘Cyclistic’:
Read the columns from the first file into a string variable;
Checked if all the files have the same set of columns (they were);
knitr::opts_chunk$set(warning = FALSE, message = FALSE)
files <- list.files('~/Google Data Analytics/8-2/Case A/Input Data/',
pattern = ".csv$", recursive = TRUE, full.names = TRUE)
str1<-
colnames(read.table(files[1], head = TRUE, nrows = 1, sep = ";"))
tb<-TRUE
invisible(lapply(files,function(x) { tb<-tb*(str1==colnames(read.table(x, head = TRUE, nrows = 1, sep = ";")))}))
print(ifelse(tb,'All columns are identical', 'Columns are not identical'))
## [1] "All columns are identical"
Merged input data into a single data frame named ‘rides’;
Checked contents of the downloaded data;
Stored the backup of original data set in ‘original_rides’.
Read and merged files from Citi Bike dataset in the same manner into data frame named ‘jc_rides’.
Removed temporary data.
rides <- read_csv(files, show_col_types = FALSE)
original_rides <- rides
files <- list.files('~/Google Data Analytics/8-2/Case A/JC_Data/',
pattern = ".csv$", recursive = TRUE, full.names = TRUE)
jc_rides <- read_csv(files, show_col_types = FALSE)
rm(str1)
rm(tb)
rm(files)
glimpse(rides)
## Rows: 5,674,449
## Columns: 13
## $ ride_id <chr> "CBCD0D7777F0E45F", "F3EC5FCE5FF39DE9", "E54C1F27FA…
## $ rideable_type <chr> "classic_bike", "electric_bike", "classic_bike", "e…
## $ started_at <dttm> 2023-02-14 11:59:42, 2023-02-15 13:53:48, 2023-02-…
## $ ended_at <dttm> 2023-02-14 12:13:38, 2023-02-15 13:59:08, 2023-02-…
## $ start_station_name <chr> "Southport Ave & Clybourn Ave", "Clarendon Ave & Go…
## $ start_station_id <chr> "TA1309000030", "13379", "TA1309000030", "TA1309000…
## $ end_station_name <chr> "Clark St & Schiller St", "Sheridan Rd & Lawrence A…
## $ end_station_id <chr> "TA1309000024", "TA1309000041", "13156", "TA1309000…
## $ start_lat <dbl> 41.92077, 41.95788, 41.92077, 41.92087, 41.79483, 4…
## $ start_lng <dbl> -87.66371, -87.64958, -87.66371, -87.66373, -87.618…
## $ end_lat <dbl> 41.90799, 41.96952, 41.88042, 41.87943, 41.78053, 4…
## $ end_lng <dbl> -87.63150, -87.65469, -87.65552, -87.63550, -87.605…
## $ member_casual <chr> "casual", "casual", "member", "member", "member", "…
Counted the number of unique ‘ride_id’ entries.
nrow(as.data.frame(unique(rides$ride_id)))
## [1] 5674449
All ‘ride_id’ values were unique.
Considering only the start points, which represent half of the stations entries:
Identified non-unique combinations of station_id and station_name;
Counted the number of unique station_id entries.
From here on, the terms ‘td’ or ‘tdf’ will refer to a ‘temporary data frame’.
td<-as.data.frame(ftable(rides$end_station_id,rides$end_station_name)) %>%
filter(Freq>0) %>%
rename(station_id=Var1,station_name=Var2) %>%
group_by (station_id) %>%
filter( n()>1) %>%
arrange(station_id)
head(td,n=10)
## # A tibble: 10 × 3
## # Groups: station_id [5]
## station_id station_name Freq
## <fct> <fct> <int>
## 1 13259 California Ave & Francis Pl 4551
## 2 13259 California Ave & Francis Pl (Temp) 617
## 3 13290 Noble St & Milwaukee Ave 5049
## 4 13290 Noble St & Milwaukee Ave (Temp) 1859
## 5 15541 Buckingham Fountain 2159
## 6 15541 Buckingham Fountain (Columbus/Balbo) 159
## 7 15541 Buckingham Fountain (Temp) 4186
## 8 15541.1.1 Buckingham - Fountain 173
## 9 15541.1.1 Buckingham Fountain 1002
## 10 15623 Campbell Ave & Montrose Ave 3223
nrow(td)
## [1] 173
td1<-as.data.frame(ftable(rides$end_station_id))
nrow(td1)
## [1] 1527
Station parameters, such as station ID, station name, latitude and longitude should be consistent all over the data set.
On the contrary, there were 173 ambiguous combinations of ‘end_station_id’ and ‘end_station_name’. This resulted in thousands of inconsistent entries, where several ‘end_station_names’ corresponded to a single ‘end_station_id’.
There were 1527 unique ‘end_station_id’ entries, which is ~2.2 times more than the real number of stations (692).
There were inconsistencies in the start station data as well.
For a further review, I generated a list of all nodes. From here on, by node I mean either end of a ride route, be it starting or ending position.
nodes = rbind (
rides %>%
select(start_station_name, start_station_id, start_lat, start_lng, member_casual) %>%
rename (station_name=start_station_name,station_id=start_station_id,lat=start_lat,lng=start_lng) %>%
mutate (point_type="start"),
rides %>% select(end_station_name, end_station_id, end_lat, end_lng, member_casual) %>%
rename (station_name=end_station_name,station_id=end_station_id,lat=end_lat,lng=end_lng) %>%
mutate(point_type="end"))
Counted number of consistent and inconsistent observations:
identified_nodes<-nodes %>%
filter(!is.na(station_name) & !is.na(station_id) & !is.na(lat) & !is.na(lng) &!lat==0 & !lng==0)
nodes_missing_latlng<- nodes %>%
filter(lat==0 | lng==0 | is.na(lat) | is.na(lng))
nodes_missing_id<-nodes %>%
filter (is.na(station_id) & !is.na(station_name))
nodes_missing_name<-nodes %>%
filter (!is.na(station_id) & is.na(station_name))
nodes_with_latlng_only=nodes %>%
filter( (is.na(station_id) | is.na(station_id) ) & !is.na(lat) & !is.na(lng) & !lat==0 & !lng==0)
nrow (identified_nodes)
## [1] 9558235
nrow (nodes_missing_latlng)
## [1] 7154
nrow (nodes_missing_id)
## [1] 273
nrow (nodes_missing_name)
## [1] 0
nrow (nodes_with_latlng_only)
## [1] 1783509
So far:
9558235 nodes had both station_id, station_name and non-zero values of longitude and latitude;
7154 nodes missed latitude and longitude. Only 119 of them had station_id and/or station_name. Other 7035 nodes were beyond repair.
273 nodes missed station_id but could have been identified via station_name.
0 nodes had station_id but no station_name.
1783509 nodes had both latitude and longitude but missed station_id and station_name.
15.6% of rides with undefined station_ID and/or no station_name was a lot. I had to check if I could identify these nodes by their spatial position and assign proper values of station_id and station_name to these entries.
In general, it is possible to use concatenation of variables ‘lat’ and ‘lng’ as unique node ID. But in this data set, latitude and longitude values jittered due to excessive precision of the positioning.
Four decimal places provide a positioning accuracy of ~11 meters. This accuracy level would have resulted in numerous combinations of ‘lat’ and ‘lng’ per station.
Three decimal places provide a positioning accuracy of ~111 meters, which seemed little bit rough.
For a further analysis of problematic data:
Rounded ‘lat’ and ‘lng’ to achieve accuracy of ~56 meters;
Concatenated ‘lat’ and ‘lng’ into ‘latlng’, the unique spatial id of the node;
Counted unique combinations of ‘lat’ and ‘lng’ in the grouped table.
identified_nodes<-identified_nodes %>%
mutate(lat=2*lat,lng=2*lng) %>%
mutate_at(vars(lat, lng), ~round(., 3)) %>%
mutate(lat=lat/2,lng=lng/2)
nodes_with_latlng_only<-nodes_with_latlng_only %>%
mutate(lat=2*lat,lng=2*lng) %>%
mutate_at(vars(lat, lng), ~round(., 3)) %>%
mutate(lat=lat/2,lng=lng/2)
identified_nodes$latlng<-paste(identified_nodes$lat,identified_nodes$lng,sep=' ')
nodes_with_latlng_only$latlng<-paste(nodes_with_latlng_only$lat,nodes_with_latlng_only$lng,sep=' ')
identified_nodes_latlng_uniques <- identified_nodes %>%
group_by (latlng) %>%
count(latlng,lat,lng) %>%
ungroup
non_identified_nodes_latlng_uniques <- nodes_with_latlng_only %>%
group_by (latlng) %>%
count(latlng,lat,lng) %>%
ungroup
Plotted identified and non-identified nodes together.
knitr::opts_chunk$set(warning = FALSE, message = FALSE)
ggplot(identified_nodes_latlng_uniques)+
geom_point(mapping=aes(x=lng,y=lat,color="identified"))+
geom_point(data=non_identified_nodes_latlng_uniques, mapping=aes(x=lng,y=lat,color="non-identified", alpha=0.2))+
ylim(41.61,42.18)+
xlim(-88.16,-87.44)+
labs(title="Spatial distribution of nodes")
Noticed something odd. Zoomed in.
knitr::opts_chunk$set(warning = FALSE, message = FALSE)
ggplot(identified_nodes_latlng_uniques)+
geom_point(mapping=aes(x=lng,y=lat,color="identified"))+
geom_point(data=non_identified_nodes_latlng_uniques, mapping=aes(x=lng,y=lat,colour="non-identified"))+
ylim(41.80,41.84)+
xlim(-87.70,-87.64)+
labs(title="Spatial distribution of nodes (zoom in)")
Longitude and latitude values of non-identified nodes were of low precision (only 2 decimals places). I was not able to attribute them to any station.
Giving up 15.6% of the data seemed like a big decision.
To do this, I had to ensure that spatial distribution and statistical parameters of the discarded data were similar to a main part of the data set.
I guessed that the subset may have had a skewed proportion of riders of different types.
round(prop.table(as.table(ftable(identified_nodes$member_casual)) ),3)
##
## casual member
## 0.354 0.646
round(prop.table(as.table(ftable(nodes_with_latlng_only$member_casual))),3)
##
## casual member
## 0.391 0.609
35 % of identified rides were performed by casual riders. 39 % of the non-identified rides were performed by casual riders. It did not seem random.
Synchronized the geolocation accuracy of both ‘identified’ and ‘unidentified’ subsets to compare them on equal terms (and use the same scale for spatial point density). ‘lp’ in the name of variables stands for ‘low precision’.
lp_identified_nodes<-identified_nodes %>%
mutate_at(vars(lat, lng), ~round(., 2))
lp_identified_nodes$latlng<-paste(lp_identified_nodes$lat, lp_identified_nodes$lng,sep=' ')
lp_identified_nodes_latlng_uniques <- lp_identified_nodes %>%
group_by (latlng) %>%
count(latlng,lat,lng) %>%
ungroup %>%
mutate( node_type = "identified")
non_identified_nodes_latlng_uniques <- non_identified_nodes_latlng_uniques %>%
mutate( node_type = "non-identified")
nodes_latlng_uniques = rbind (lp_identified_nodes_latlng_uniques, non_identified_nodes_latlng_uniques)
rm(lp_identified_nodes)
rm(lp_identified_nodes_latlng_uniques)
ggplot(nodes_latlng_uniques)+
geom_point(mapping=aes(x=lng,y=lat,colour=n, fill=n, alpha=n))+
ylim(41.61,42.18)+
xlim(-88.16,-87.44)+
labs(title='Low precision map of starting and ending points')+
facet_wrap(node_type~.)
The two subsets were indeed different. Non-identified nodes were scattered away.
I decided to keep the subset of non-identified rides in analytics. Unfortunately, these rows were of no use for station traffic analysis.
For further analysis, I identified and merged duplicate station_ids.
Here’s the sequence of manipulations.
freq_id<-as.data.frame(ftable(identified_nodes$station_id)) %>%
rename(id=Var1, n_id=Freq)
nrow(freq_id)
## [1] 1542
Assumed that any ‘station_id’ was identified by the most common ‘station name’ and most common ‘latlng’ values.
Found values of ‘latlng’ that correspond to two or more ‘station_id’ and identified the most frequent ‘station_id’ values among this subset.
latlng_per_id<-as.data.frame(ftable(identified_nodes$latlng, identified_nodes$station_id)) %>%
filter(Freq>0) %>%
rename(latlng=Var1, id=Var2) %>%
group_by(id) %>%
arrange(id,desc(Freq)) %>%
top_n(1, Freq) %>%
rename (n_latlng=Freq) %>%
distinct (id, .keep_all=TRUE)
name_per_id<-as.data.frame(ftable(identified_nodes$station_name, identified_nodes$station_id)) %>%
filter(Freq>0) %>%
rename(name=Var1, id=Var2) %>%
group_by(id) %>%
arrange(id,desc(Freq)) %>%
top_n(1, Freq) %>%
rename (n_name=Freq) %>%
distinct (id, .keep_all=TRUE)
idnamelatlng <- merge(merge(freq_id,latlng_per_id, by="id"),name_per_id, by="id") %>%
arrange(desc(n_id))
td <- idnamelatlng %>%
group_by (name) %>%
slice(which.max(n_id)) %>%
select (name, id)
idnamelatlng <- idnamelatlng %>%
rename(orig_id=id)
idnamelatlng<-merge(idnamelatlng,td,by="name")
td <- idnamelatlng %>%
arrange(desc(n_id)) %>%
distinct(id,.keep_all=TRUE) %>%
group_by (latlng) %>%
slice(which.max(n_id)) %>%
select (latlng, id)
idnamelatlng <- idnamelatlng %>%
rename(interim_id=id)
idnamelatlng<-merge(idnamelatlng,td,by="latlng")
idnamelatlng <- idnamelatlng %>%
rename(orig_name=name,orig_n_id=n_id,orig_latlng=latlng)
idnamelatlng<-merge(idnamelatlng,latlng_per_id %>% select(!n_latlng),by="id")
idnamelatlng<-merge(idnamelatlng,name_per_id %>% select(!n_name),by="id")
idnamelatlng <-idnamelatlng[, c("orig_id","orig_n_id","orig_latlng","n_latlng","orig_name","n_name","interim_id", "id", "latlng", "name")]
rm(freq_id)
rm(latlng_per_id)
rm(name_per_id)
idnamelatlng[c('lat', 'lng')] <- str_split_fixed(idnamelatlng$latlng, ' ', 2)
idnamelatlng<- transform(idnamelatlng,lat=as.numeric(lat),lng=as.numeric(lng))
#view_merges is a temporary data frame needed only for a visualization of changes
view_merges <- idnamelatlng %>%
group_by(id) %>%
filter( n()>1) %>%
arrange(id)
idnamelatlng<- idnamelatlng %>%
select(orig_id,id,name,lat,lng)
view_merges <- merge (view_merges,
view_merges %>%
group_by (id) %>%
summarize(n_id=sum(orig_n_id))) %>%
arrange(desc(n_id), desc(orig_n_id))
view_merges<-view_merges[, c("orig_id","orig_n_id","orig_latlng","n_latlng","orig_name","n_name","interim_id", "id", "n_id", "latlng", "lat", "lng", "name")]
td<-head(view_merges, n=7)
td$orig_id <-factor(td$orig_id, levels=td$orig_id)
col.par = function(n) sample(seq(0.3, 1, length.out=50),n)
cols = rainbow(13, s=col.par(13), v=col.par(13))[sample(1:13,13)]
ggplot(td, aes(x=name, y=orig_n_id, fill=orig_name)) +
geom_col()+
scale_fill_manual(values=cols)+
theme(axis.text.x = element_text(angle = 45, vjust = 1, hjust=1))+
labs(title="Merging non-unique station_ids")
#rm(view_merges)
nrow(as.data.frame(unique(idnamelatlng$id)))
## [1] 1486
For example, 69,919 observations named “Clark St & Elm St” and 859 observations named “N Clark St & W Elm St” had similar ‘latitude’ and ‘longitude’.
Merged them into a single category defined by the combination of the most frequent values of ‘station_id’, ‘name’, ‘latitude’ and ‘longitude’, specifically, [“TA1307000039”, “Clark St & Elm St”, 41.903, -87.631].
Total number of unique ‘station_id’ entries reduced from 1542 to 1486. It was still far from the number 692 mentioned by stakeholders. (A question to be asked).
Filled the main data frame ‘rides’ with consistent information about station_id, station_name, station_latitude and station_longitude.
Calculated a “distance” between station coordinates and ride start or end points if they were attributed to a station. This column is needed to identify the outliers erroneously attributed to a station. (Note that “distance” was not truly a distance, because it was measured in degrees, not meters or miles).
rides<- rides %>%
rename(orig_end_station_id=end_station_id, orig_end_station_name=end_station_name) %>%
rename(orig_start_station_id=start_station_id, orig_start_station_name=start_station_name)
rides<- left_join(rides,
idnamelatlng %>%
rename(orig_start_station_id=orig_id, start_station_id=id, start_station_name=name, start_station_lat=lat, start_station_lng=lng),
by="orig_start_station_id")
rides<- left_join(rides,
idnamelatlng %>%
rename(orig_end_station_id=orig_id, end_station_id=id, end_station_name=name, end_station_lat=lat, end_station_lng=lng),
by="orig_end_station_id")
rides <- rides %>%
mutate (start_distance_to_station=((start_lat-start_station_lat)^2+(start_lng-start_station_lng)^2) ^(1/2),
end_distance_to_station=((end_lat-end_station_lat)^2+(end_lng-end_station_lng)^2) ^(1/2))
Calculated columns for:
weekdays,
months,
‘hours’ (numeric),
‘time of the day’ (string),
travel distance,
average travel speed of the ride.
For calculating travel distance (km) based on longitude and latitude, I had to convert degrees to radians.
knitr::opts_chunk$set(warning = FALSE, message = FALSE)
rides <- rides %>%
mutate(weekday=c("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday")[as.POSIXlt(rides$started_at)$wday + 1]) %>%
# take a note that business day calculation is far from perfect and does not account for holidays
mutate(bizday=c("Weekend", "Business day", "Business day", "Business day", "Business day", "Business day", "Weekend")[as.POSIXlt(rides$started_at)$wday + 1]) %>%
mutate(month=as.factor(c("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec")[as.POSIXlt(rides$started_at)$mon + 1] )) %>%
mutate(hours= as.integer(format(as.POSIXct(started_at), format = "%H"))) %>%
mutate(duration=ended_at-started_at) %>%
mutate(travel_distance=as.numeric(round(acos(sin(deg2rad(start_lat))*sin(deg2rad(end_lat))+cos(deg2rad(start_lat))*cos(deg2rad(end_lat))*cos(deg2rad(end_lng)-deg2rad(start_lng)))*6371 *1000 ,digits=0))) %>%
mutate(travel_distance = ifelse(is.nan(travel_distance), 0, travel_distance)) %>%
mutate(avg_travel_speed = travel_distance/as.numeric(duration)*3600/1000)
rides$time_of_the_day <- factor(x=rides$hours, levels=sort(unique(rides$hours)), labels = c("12AM", "1AM", "2AM", "3AM", "4AM", "5AM", "6AM", "7AM", "8AM", "9AM", "10AM", "11AM", "12PM", "1PM", "2PM", "3PM", "4PM", "5PM", "6PM", "7PM", "8PM", "9PM", "10PM", "11PM") )
months_as_factor = factor(rides$month, ordered=TRUE, levels=c("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"))
Citi Bike data frame was transformed in a similar manner.
jc_rides <- jc_rides %>%
mutate(bizday=c("Weekend", "Business day", "Business day", "Business day", "Business day", "Business day", "Weekend")[as.POSIXlt(jc_rides$started_at)$wday + 1]) %>%
mutate(month=as.factor(c("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec")[as.POSIXlt(jc_rides$started_at)$mon + 1] )) %>%
mutate(hours= as.integer(format(as.POSIXct(started_at), format = "%H"))) %>%
mutate(duration=ended_at-started_at) %>%
mutate(travel_distance=as.numeric(round(acos(sin(deg2rad(start_lat))*sin(deg2rad(end_lat))+cos(deg2rad(start_lat))*cos(deg2rad(end_lat))*cos(deg2rad(end_lng)-deg2rad(start_lng)))*6371 *1000 ,digits=0))) %>%
mutate(travel_distance = ifelse(is.nan(travel_distance), 0, travel_distance)) %>%
mutate(avg_travel_speed = travel_distance/as.numeric(duration)*3600/1000)
Cleaned the main data frame. Number of rows before cleaning:
nrow(rides)
## [1] 5674449
Removed rows with:
no latitude and longitude of the starting or ending point,
zero latitude and longitude values,
unrealistic speed or duration of ride,
start point or end point erroneously attributed to incorrect station.
rides <- rides %>%
filter(!is.na(member_casual) & !is.na(start_lat) & !is.na(end_lat) & !is.na(start_lng) & !is.na(end_lng) & !(start_lat==0) & !(end_lat==0)& !(start_lng==0) & !(end_lng==0) & (duration>0)) %>%
filter( avg_travel_speed<50 & duration < 3600*24*2) %>%
filter (!( !is.na(start_distance_to_station) & !is.na(end_distance_to_station) & (start_distance_to_station>0.01 | end_distance_to_station>0.01))) %>%
select (!contains('orig'))
rm(nodes, identified_nodes, identified_nodes_latlng_uniques, nodes_latlng_uniques, nodes_missing_id, nodes_missing_latlng, nodes_missing_name, nodes_with_latlng_only, non_identified_nodes_latlng_uniques, td, td1)
nrow(rides)
## [1] 5648082
After the cleaning, main data frame comprised 5,648,082 rows.
Excluded 26,367 rows, or 0.46% of the data.
The Citi Bike data frame was processed in the same manner.
jc_rides <- jc_rides %>%
filter(!is.na(member_casual) & !is.na(start_lat) & !is.na(end_lat) & !is.na(start_lng) & !is.na(end_lng) & !(start_lat==0) & !(end_lat==0)& !(start_lng==0) & !(end_lng==0) & (duration>0)) %>%
filter( avg_travel_speed<50 & duration < 3600*24*2)
With clean data, reconstructed the ‘nodes’ data frame for the analytics of spatial distribution of rides.
Chosen a 2 decimal places precision for latitude and longitude.
nodes<- rbind (rides %>%
select(start_lat, start_lng, member_casual) %>%
rename (lat=start_lat,lng=start_lng) %>%
mutate (point_type="start"),
rides %>%
select(end_lat, end_lng, member_casual) %>%
rename (lat=end_lat,lng=end_lng) %>%
mutate(point_type="end")) %>%
mutate_at(vars(lat, lng), ~round(., 2))
nodes$latlng<-paste(nodes$lat,nodes$lng,sep=' ')
nodes$point_type_member_casual<-paste(nodes$point_type,nodes$member_casual,sep=' ')
For any unique node, assigned number of starts and ends of rides by member/casual rider.
td <- nodes %>%
group_by (latlng,point_type_member_casual) %>%
count(latlng,point_type_member_casual) %>%
ungroup
nodes <- nodes %>%
select(latlng, lat, lng) %>%
count(latlng, lat, lng)
nodes <- full_join (nodes,
td %>%
filter(point_type_member_casual=="start member") %>%
select(latlng, n) %>%
rename(n_start_member=n))
nodes <- full_join(nodes,
td %>%
filter(point_type_member_casual=="end member") %>%
select(latlng, n) %>%
rename(n_end_member=n))
nodes <- full_join(nodes,
td %>%
filter(point_type_member_casual=="start casual") %>%
select(latlng, n) %>%
rename(n_start_casual=n))
nodes <- full_join(nodes,
td %>%
filter(point_type_member_casual=="end casual") %>%
select(latlng, n) %>%
rename(n_end_casual=n))
Plotted spatial density of rides.
nodes<-nodes %>%
mutate_all(~replace(., is.na(.), 0)) %>%
mutate(casual_percentage=(n_end_casual+n_start_casual)/n) %>%
mutate(norm_ride_density=n/517457)
ggplot(nodes)+
geom_point(mapping=aes(x=lng,y=lat,color=casual_percentage,size=n,alpha=n))+
ylim(41.61,42.18)+
xlim(-88.16,-87.44)+
labs(title="Casual riders tend to use bikes at peripheral areas")+
scale_color_continuous(high="red", low="yellow")+
scale_size_continuous(range = c(0.9,4))+
scale_alpha_continuous(range = c(0.5,1))
It was clear that the most of the activities of the Cyclistic clients were concentrated in the city center.
nodes <- nodes %>%
mutate (nodes, zones=c("Periphery", "Center")[(as.integer( (((lat-41.94)^2+(lng+87.64)^2)^(0.5) <0.028)|(((lat-41.89)^2+(lng+87.64)^2)^(0.5) <0.044)))+1])
rides <- rides %>%
mutate(start_zone=as.character ( as.integer( (((start_lat-41.94)^2+(start_lng+87.64)^2)^(0.5) <0.028)|(((start_lat-41.89)^2+(start_lng+87.64)^2)^(0.5) <0.044) ) )) %>%
mutate(end_zone=as.character ( as.integer( (((end_lat-41.94)^2+(end_lng+87.64)^2)^(0.5) <0.028)|(((end_lat-41.89)^2+(end_lng+87.64)^2)^(0.5) <0.044) ) ))
rides$travel_type<-paste(c("at the periphery", "To/From center", "Within center")[as.integer(rides$start_zone)+as.integer(rides$end_zone)+1])
rides$travel_type_binary<-paste(c("To/From/Within center", "at the periphery")[ (1- as.integer(rides$start_zone))*(1-as.integer(rides$end_zone))+1])
nodes[is.na(nodes)] <- 0
td<- nodes %>%
group_by(zones) %>%
summarise(casual_rides_per_node = mean( (n_start_casual+n_end_casual)) , members_ride_per_node = mean( (n_start_member+n_end_member))) %>%
as.data.frame()
row.names(td)<-td$zones
ggplot(nodes) +
geom_point(mapping=aes(x=lng,y=lat,colour=zones,fill=zones,size=n, alpha=n))+
ylim(41.61,42.18)+
xlim(-88.16,-87.44)+
labs(title="Central and peripheral zones",subtitle="Ride density in city center is higher")+
#scale_color_continuous(high="red", low="yellow")+
scale_size_continuous(range = c(0.9,4))+
scale_alpha_continuous(range = c(0.5,1))+
scale_colour_manual( values = c( "#00A4CCFF", "#F95700FF"))
round(td %>% select(!zones))
## casual_rides_per_node members_ride_per_node
## Center 43791 77065
## Periphery 1324 2434
Divided area into two zones:
City center with high ride density.
Periphery with lower ride density.
The city center zone is concatenation of two circles. First circle is centered at [41.89,-87.64] and has radius equal to 0.044 degrees. Second circle has center in [41.94.-87.64] and radius of 0.028 degrees. These values were selected manually.
ggplot(nodes %>% filter(n_end_casual==1 ) )+
geom_point(mapping=aes(x=lng,y=lat,colour="red"))+
ylim(41.61,42.18)+
xlim(-88.16,-87.44)+
labs(title="Most of the outlier end points correspond to casual rides",subtitle="In general, casual riders are more likely to leave bikes far from stations and public racks")+
geom_point(data=nodes %>% filter(n_end_member==1 ), mapping=aes(x=lng,y=lat,colour="blue"))+
scale_color_manual(labels = c("casual riders", "members"), values = c( "red", "blue"))
Interesting fact: if the bike was left somewhere very far from stations, public racks, then it was almost certainly done by a casual rider.
The next leaflet depicts the most unusual spots, where a casual ride ended, including highways, railroads and Lake Michigan.
td<-nodes %>%
filter(n_end_casual==1)
leaflet() %>%
addTiles() %>% #' Add default OpenStreetMap map tiles
addMarkers(lng=td$lng, lat=td$lat)
Checked monthly patterns in Chicago.
rides_per_day <- rides %>%
select(started_at, month, member_casual, travel_type, travel_type_binary, bizday, hours, rideable_type) %>%
mutate(ride_date=as.Date.POSIXct(started_at) ) %>%
group_by(ride_date, month, member_casual, travel_type, travel_type_binary, bizday, hours, rideable_type) %>%
summarize(rides_count = n()) %>%
ungroup
tdf<-rides_per_day %>%
group_by(ride_date, month, member_casual, bizday) %>%
summarize(rides_count = sum(rides_count) ) %>%
ungroup
tdf<-tdf %>%
group_by(month, member_casual, bizday) %>%
summarize(avg_rides_count = round(mean(rides_count),0) ) %>%
ungroup
tdf$month = factor(tdf$month, levels = month.abb)
ggplot(data=tdf, mapping=aes(x=month,y=avg_rides_count,fill=member_casual))+
geom_bar(stat="identity",position=position_dodge())+
ylim(0,16000)+
facet_wrap(bizday~.)+
labs(title="Chicago monthly patterns",subtitle="Average number of rides per day")
Casual riding decreases during winter, indicating it’s more of a leisure activity. Casual riders activity increases on weekends, Cyclistic members stays the same or drops insignificantly.
The leisure cyclists ride for leisure, prefer warm weather and more active during weekends. It seemed reasonable to assume that a significant part of the weekend rides are leisure rides. The presence of leisure cyclists among the members demonstrates the **attractiveness of membership**for them. Nevertheless, Cyclistic struggles to convert casual clients into members.
There are also regular everyday cyclists. It is a category of cyclists who ride for their everyday errands, regardless of the month or weather.
There are commuting cyclists. It is a category of clients who ride predominantly on weekdays, regardless of the month or weather.
Finally, inactive members are the members who pay for membership but rarely ride or do not ride at all. For the current study, they are practically invisible.
It is important to find the difference between those leisure cyclists who are already in the program and those who aren’t. On weekends, both groups are seemingly equally active from May to September. The member rides to casual rides ratio is about 1:1. Both groups become less active in cold months, but Cyclistic members are way more tolerant to weather. In January, the member to casual ratio rises dramatically to almost 4:1.
The number of unique casual clients must be higher than the number of unique leisure cyclists among Cyclistic members, despite the seemingly equal number of ‘leisure rides’ in both categories.
jc_rides_per_day <- jc_rides %>%
select(started_at, month, member_casual, bizday, hours) %>%
mutate(ride_date=as.Date.POSIXct(started_at) ) %>%
group_by(ride_date, month, member_casual, bizday, hours) %>%
summarize(rides_count = n()) %>%
ungroup
tdf<-jc_rides_per_day %>%
group_by(ride_date, month, member_casual, bizday) %>%
summarize(rides_count = sum(rides_count) ) %>%
ungroup
tdf<-tdf %>%
group_by(month, member_casual, bizday) %>%
summarize(avg_rides_count = round(mean(rides_count),0) ) %>%
ungroup
tdf$month = factor(tdf$month, levels = month.abb)
ggplot(data=tdf, mapping=aes(x=month,y=avg_rides_count,fill=member_casual))+
geom_bar(stat="identity",position=position_dodge())+
ylim(0,16000)+
facet_wrap(bizday~.)+
labs(title="Jersey City monthly patterns",subtitle="Average number of rides per day")
Compared Chicago Cyclistic patterns to the Citi Bike data.
In Jersey City, the member-to-casual ratio is higher. This is likely because the Cyclistic bike share program is more popular among Chicago residents than the Citi Bike program is among Jersey City residents.
Calculated average ride count per hour to analyze daily patterns:
tdf<-rides_per_day %>%
filter (travel_type_binary=="To/From/Within center") %>%
group_by(ride_date, hours, member_casual, bizday) %>%
summarize(rides_count = sum(rides_count) ) %>%
ungroup
tdf<-tdf %>%
group_by(hours, member_casual, bizday) %>%
summarize(avg_rides_count = round(mean(rides_count),0) ) %>%
ungroup
tdf$hours = factor(tdf$hours)
tdf2<-rides_per_day %>%
filter (travel_type_binary=="at the periphery") %>%
group_by(ride_date, hours, member_casual, bizday) %>%
summarize(rides_count = sum(rides_count) ) %>%
ungroup
tdf2<-tdf2 %>%
group_by(hours, member_casual, bizday) %>%
summarize(avg_rides_count = round(mean(rides_count),0) ) %>%
ungroup
tdf2$hours = factor(tdf2$hours)
ggplot(data=tdf, mapping=aes(x=hours,y=avg_rides_count,fill=member_casual))+
geom_bar(stat="identity",position=position_dodge())+
ylim(0,1100)+
facet_wrap(bizday~.)+
labs(title="Chicago daily patterns in downtown",subtitle="Average number of rides per hour")
On business days, commuting cyclists show two peaks of activity, before and after work. (From prior information, it is known that 30% of the users commute to work each day using bikes). Casual riders tend to use bikes mostly during the second half of the day.
Weekend daily patterns of casual riders and Cyclistic members are almost indistinguishable based on this chart.
Commuting to work by bike is more common in the city center.
ggplot(data=tdf2, mapping=aes(x=hours,y=avg_rides_count,fill=member_casual))+
geom_bar(stat="identity",position=position_dodge())+
ylim(0,1100)+
facet_wrap(bizday~.)+
labs(title="Chicago daily patterns at the periphery",subtitle="Average number of rides per hour")
At the periphery, members to casual ratio is higher than in the city center. From comparison with Citi Bike data, this may be a sign of low market penetration rate. The first customers are enthusiasts, who are more likely to buy membership.
ggplot(data=tdf %>% filter(member_casual=="casual", bizday=="Business day"), mapping=aes(x=hours,y=avg_rides_count,fill=member_casual))+
geom_bar(stat="identity",position=position_dodge())+
# ylim(0,1300)+
# facet_wrap(bizday~.)+
labs(title="Limited potential to involve more weekly cyclists",subtitle="Average number of **casual** rides per hour **within city center**")+
annotate(geom="text",x=8.5,y=300,label="Note the small peak at 8 a.m. \n\nSome casual riders follow\nregular weekday cyclists pattern\nand commute to work by bike \n in the morning\n",size=3)
There are commuting casual riders, too. Some casual riders commute to work by bike in the morning on business days. However, it is safe to conclude that the majority of the commuting cyclists is already in the club.
tdf<-jc_rides_per_day %>%
group_by(ride_date, hours, member_casual, bizday) %>%
summarize(rides_count = sum(rides_count) ) %>%
ungroup
tdf<-tdf %>%
group_by(hours, member_casual, bizday) %>%
summarize(avg_rides_count = round(mean(rides_count),0) ) %>%
ungroup
tdf$hours = factor(tdf$hours)
ggplot(data=tdf, mapping=aes(x=hours,y=avg_rides_count,fill=member_casual))+
geom_bar(stat="identity",position=position_dodge())+
ylim(0,1100)+
facet_wrap(bizday~.)+
labs(title="Jersey City daily patterns",subtitle="Average number of rides per hour")
Citi Bike data demonstrated the repetitiveness of daily pattern, indicating consistent usage habits among the riders.
tdf<-rides_per_day %>%
group_by(ride_date, hours, member_casual, bizday, rideable_type) %>%
summarize(rides_count = sum(rides_count) ) %>%
ungroup
tdf<-tdf %>%
group_by(hours, member_casual, bizday, rideable_type) %>%
summarize(avg_rides_count = round(mean(rides_count),0) ) %>%
ungroup
tdf$hours = factor(tdf$hours)
tdf$rideable_type = factor(tdf$rideable_type, ordered=TRUE, levels = c("classic_bike","electric_bike","docked_bike"))
ggplot(data=tdf, mapping=aes(x=hours,y=avg_rides_count,fill=member_casual))+
geom_bar(stat="identity",position=position_dodge())+
facet_wrap(bizday~rideable_type)+
labs(title="Popularity of different types of bikes",subtitle="Only casual riders prefer docked bikes")
Docked bikes are only used by casual riders.
tdf <-
rbind(
rides %>%
group_by(member_casual) %>%
summarise(average_distance=mean(travel_distance),average_speed=mean(avg_travel_speed),average_duration=mean(duration) ) %>%
as.data.frame() %>%
mutate (city="Chicago"),
jc_rides %>%
group_by(member_casual) %>%
summarise(average_distance=mean(travel_distance),average_speed=mean(avg_travel_speed),average_duration=mean(duration) ) %>%
as.data.frame() %>%
mutate (city="Jersey City"))
ggplot(data=tdf, mapping=aes(x=city,y=average_duration,fill=member_casual))+
geom_bar(stat="identity",position=position_dodge())+
labs(title="Average ride duration")
Casual bike rides are longer.
tdf<-
rbind (
rides %>%
select(avg_travel_speed, member_casual) %>%
mutate(city='Chicago'),
jc_rides %>%
select(avg_travel_speed, member_casual) %>%
mutate(city='Jersey City')
)
ggplot(data = tdf , aes(x = avg_travel_speed, fill=member_casual)) +
geom_density(alpha=0.2)+
xlim(0,25)+
ylim(0,0.15)+
labs(title="Distribution of the travel speed for both types of clients" )+
facet_wrap(~city)
Speed: Cyclistic members typically outpace casual riders, a trend that holds true even on weekends. This is likely a result of their regular cycling habits and training.
Ride Frequency: The enhanced training of Cyclistic members can be explained naturally by a higher ride frequency.
Number of Unique Clients: Despite similar numbers of weekend rides, the lower frequency of rides per individual casual rider suggests that the total number of casual riders is greater. This indicates a broader target audience.
Marketing Approach: The less enthusiastic casual riders require a different marketing strategy.
Chicago vs. Jersey City: Unlike Jersey City, Chicago might see a larger speed difference between club members and casual riders. This could be due to a higher proportion of untrained, regular cyclists among casual riders in Chicago and the prevalence of longer, slower rides in the city.
Moved on to identify the most popular destinations among casual customers and Cyclistic members during peak hours on business days.
rides_per_station <- rides %>%
filter(!is.na(end_station_id)) %>%
group_by (end_station_id, end_station_name, member_casual, hours, bizday) %>%
summarize(n= sum(n())) %>%
ungroup
bizday_rush_hours_rides <-
rides_per_station %>%
filter((hours==7 | hours==8) & bizday=="Business day" ) %>%
group_by(end_station_id,end_station_name,member_casual) %>%
summarize (n=sum(n)) %>%
ungroup %>%
group_by(end_station_name)
tdf <- bizday_rush_hours_rides %>%
group_by(end_station_id, end_station_name) %>%
summarize(n=sum(n)) %>%
ungroup %>%
top_n (10, n)
tdf2 <- bizday_rush_hours_rides %>%
filter(end_station_id %in% tdf$end_station_id)
tdf <-
full_join(bizday_rush_hours_rides %>%
filter(member_casual=="member") %>%
select(!member_casual) %>%
rename(n_member=n),
bizday_rush_hours_rides %>%
filter(member_casual=="casual") %>%
select(end_station_id, n) %>%
rename(n_casual=n)
)
tdf$n_member[is.na(tdf$n_member)]<-0
tdf$n_casual[is.na(tdf$n_casual)]<-0
tdf <- tdf %>%
mutate(n=n_casual+n_member)
casual_threshold<-700
member_threshold<-3700
common_places_during_bizday_rush_hours <-
inner_join(
tdf %>%
filter(n_casual>casual_threshold),
tdf %>%
filter(n_member>member_threshold)
)
common_places_during_bizday_rush_hours <-
left_join(
common_places_during_bizday_rush_hours %>%
select (end_station_id),
idnamelatlng %>%
rename(end_station_id=id)
)
ggplot(tdf2 , aes(x=fct_reorder(end_station_name,n), y=n, fill=member_casual)) +
geom_bar(stat="identity") +
coord_flip()+
labs(title="Most popular destinations during rush hours on weekdays",x=" ")
During morning rush hours on weekdays, member trips prevail, accounting for 85% of the total at the busiest stations.
model <- lm(n_casual ~ n_member, data = tdf %>% filter(n>1000))
r_squared <- summary(model)$r.squared
ggplot (tdf %>% filter(n>1000), aes(n_member, y=n_casual)) +
geom_rect(aes(xmin=0,xmax=member_threshold,ymin=casual_threshold,ymax=1700),fill="#FFEEEE",alpha=0.1)+
geom_rect(aes(xmin=member_threshold,xmax=7000,ymin=casual_threshold,ymax=1700),fill="#FFEEFF",alpha=0.1)+
geom_rect(aes(xmin=member_threshold,xmax=7000,ymin=0000,ymax=1700),fill="#EEEEFF",alpha=0.1)+
geom_point()+
# stat_cor(method = "pearson", label.x = 4000, label.y = 200)+
annotate("text", x = 4000, y = 200, label = paste("R-squared =", round(r_squared, 2)))+
geom_text_repel(
data=tdf %>% filter(n_casual>casual_threshold | n_member>member_threshold), # Filter data first
aes(label=end_station_name, hjust=0), position = position_nudge(x = 100))+
annotate("text",x=10,y=1700-10,label="Popular\namong\ncasual riders",color="#FFAAAA", hjust=0, vjust=1)+
annotate("text",x=7000-10,y=1700-10,label="Popular among both casual riders\nand club members",color="#FFAAFF", hjust=1,vjust=1)+
annotate("text",x=7000-10,y=10,label="Popular\namong club members",color="#AAAAFF", hjust=1, vjust=0)+
labs(title="Number of casual clients vs Number of members during rush hours")+
labs(title="Popular destinations during morning rush hours")
The end destinations of rides for both casual riders and members are very much similar. The correlation between the numbers of rides per station for different groups cannot be denied: R-squared=0.69.
leaflet() %>%
addTiles() %>% #' Add default OpenStreetMap map tiles
addMarkers(lng=common_places_during_bizday_rush_hours$lng, lat=common_places_during_bizday_rush_hours$lat, popup=common_places_during_bizday_rush_hours$end_station_name)
Places that are popular among both categories during business day morning rush hours are depicted on a leaflet above. They include:
Canal St & Jackson Blvd
Kingsbury St & Kinzie St
Dearborn St & Monroe St
Orleans St & Merchandise Mart Plaza
Larrabee St & Kingsbury St
Franklin St & Lake St
Wells St & Hubbard St
Franklin St & Monroe St
Clinton St & Washington Blvd
All these places are located near the central business district of Chicago, often referred to as the Loop. This area is known for its high concentration of businesses, shopping, entertainment, and cultural venues. It’s also where many of the city’s most iconic buildings and landmarks, such as the Willis Tower and Union Station, are located. The Loop is bounded by the Chicago River to the north and west, Harrison Street to the south, and Lake Michigan to the east. So, these places are all in the heart of downtown Chicago.
The next step was to review the weekend data.
weekend_rides <-
rides_per_station %>%
filter(bizday=="Weekend" ) %>%
group_by(end_station_id,end_station_name,member_casual) %>%
summarize (n=sum(n)) %>%
ungroup %>%
group_by(end_station_name)
tdf <- weekend_rides %>%
group_by(end_station_id, end_station_name) %>%
summarize(n=sum(n)) %>%
ungroup %>%
top_n (10, n)
tdf2 <- weekend_rides %>%
filter(end_station_id %in% tdf$end_station_id)
tdf <-
full_join(weekend_rides %>%
filter(member_casual=="member") %>%
select(!member_casual) %>%
rename(n_member=n),
weekend_rides %>%
filter(member_casual=="casual") %>%
select(end_station_id, n) %>%
rename(n_casual=n)
)
tdf$n_member[is.na(tdf$n_member)]<-0
tdf$n_casual[is.na(tdf$n_casual)]<-0
tdf <- tdf %>%
mutate(n=n_casual+n_member)
casual_threshold<-5000
member_threshold<-5000
common_places_during_weekends <-
inner_join(
tdf %>% filter(n_casual>casual_threshold),
tdf %>% filter(n_member>member_threshold)
)
common_places_during_weekends <-
left_join(
common_places_during_bizday_rush_hours %>% select (end_station_id),
idnamelatlng %>% rename(end_station_id=id)
)
ggplot(tdf2 , aes(x=fct_reorder(end_station_name,n), y=n, fill=member_casual)) +
geom_bar(stat="identity") +
coord_flip()+
labs(title="Most popular destinations on weekends",x=" ")
Casual member activity prevails on weekends.
The most popular places among casual riders are:
Streeter Dr & Grand Ave
DuSable Lake Shore Dr & Monroe St
Michigan Ave & Oak St
Millennium Park
DuSable Lake Shore Dr & North Blvd
Theater on the Lake
Shedd Aquarium
Dusable Harbor
Clark St & Lincoln Ave
Montrose Harbor
The leaflet below depicts the most popular places among casual riders on weekends:
tdf2 <- tdf %>%
filter(n_casual>casual_threshold)
tdf2 <-
left_join(
tdf2 %>% select (end_station_id),
idnamelatlng %>% rename(end_station_id=id)
)
leaflet() %>%
addTiles() %>% #' Add default OpenStreetMap map tiles
addMarkers(lng=tdf2$lng, lat=tdf2$lat, popup=tdf2$end_station_name)
These places are all located along the Lake Michigan shoreline in Chicago. They are part of the city’s Lakefront Trail, an 18-mile multi-use trail that runs alongside the shoreline. This trail is a popular spot for biking, jogging, and walking, offering stunning views of the lake and the city skyline. It passes through various parks and recreational spots, including Millennium Park, Theater on the Lake, and Shedd Aquarium. So, these places are all part of Chicago’s vibrant and scenic lakefront area.
model <- lm(n_casual ~ n_member, data = tdf %>% filter(n>2000))
r_squared <- summary(model)$r.squared
ggplot (tdf %>% filter(n>2000), aes(n_member, y=n_casual)) +
geom_rect(aes(xmin=0,xmax=casual_threshold,ymin=member_threshold,ymax=25000),fill="#FFEEEE",alpha=0.1)+
geom_rect(aes(xmin=casual_threshold,xmax=9000,ymin=member_threshold,ymax=25000),fill="#FFEEFF",alpha=0.1)+
geom_rect(aes(xmin=casual_threshold,xmax=9000,ymin=0000,ymax=member_threshold),fill="#EEEEFF",alpha=0.1)+
geom_point()+
# stat_cor(method = "pearson", label.x = 400, label.y = 15000)+
annotate("text", x = 1400, y = 15000, label = paste("R-squared =", round(r_squared, 2)))+
geom_text_repel(
data=tdf %>% filter(n_casual>casual_threshold | n_member>member_threshold), # Filter data first
aes(label=end_station_name, hjust=0), position = position_nudge(x = 100))+
xlim(0,9000)+
ylim(0,25000)+
annotate("text",x=100,y=24800,label="Popular\namong\ncasual riders",color="#FFAAAA", hjust=0, vjust=1)+
annotate("text",x=8900,y=24800,label="Popular\namong both casual riders\nand club members",color="#FFAAFF", hjust=1, vjust=1)+
annotate("text",x=8900,y=200,label="Popular\namong club members",color="#AAAAFF", hjust=1, vjust=0)+
labs(title="Popular destinations on weekends")
During weekends, the spatial pattern of casual rides and member rides differ a lot. The correlation coefficient between the numbers of rides per station for different groups is quite low: R-squared=0.29, telling that these categories of people are different indeed.
The most popular places among Cyclistic members are:
Wells St & Concord Ln
Clark St & Elm St
Streeter Dr & Grand Ave
Broadway & Barry Ave
DuSable Lake Shore Dr & North Blvd
Wells St & Elm St
Theater on the Lake
Kingsbury St & Kinzie St
Clark St & Lincoln Ave
Clark St & Armitage Ave
There are few intersections, but, generally, this is a different set. These places are all located in the Near North Side of Chicago. This area is known for its high concentration of businesses, shopping, entertainment, and cultural venues. It’s also where many of the city’s most iconic buildings and landmarks are located1. The Near North Side includes neighborhoods like Old Town, which is home to many of Chicago’s older, Victorian-era buildings. So, these places are all in a vibrant and historically rich part of Chicago.
The leaflet below depicts the most popular places among both casual riders and Cyclistic members during weekends.
leaflet() %>%
addTiles() %>% #' Add default OpenStreetMap map tiles
addMarkers(lng=common_places_during_weekends$lng, lat=common_places_during_weekends$lat, popup=common_places_during_weekends$end_station_name)
Finally, analyzed spatial patterns of everyday cyclists during a regular weekday, excluding rush hours.
everyday_rides <-
rides_per_station %>%
filter( !(hours==7 | hours==8 | hours==16 |hours==17 |hours==18 ) & bizday=="Business day" ) %>%
group_by(end_station_id,end_station_name,member_casual) %>%
summarize (n=sum(n)) %>%
ungroup %>%
group_by(end_station_name)
tdf <- everyday_rides %>%
group_by(end_station_id, end_station_name) %>%
summarize(n=sum(n)) %>%
ungroup %>%
top_n (10, n)
tdf2 <- everyday_rides %>%
filter(end_station_id %in% tdf$end_station_id)
tdf <-
full_join(everyday_rides %>%
filter(member_casual=="member") %>%
select(!member_casual) %>%
rename(n_member=n),
everyday_rides %>%
filter(member_casual=="casual") %>%
select(end_station_id, n) %>%
rename(n_casual=n)
)
tdf$n_member[is.na(tdf$n_member)]<-0
tdf$n_casual[is.na(tdf$n_casual)]<-0
tdf <- tdf %>%
mutate(n=n_casual+n_member)
casual_threshold<-5000
member_threshold<-7000
common_everyday_places <-
inner_join(
tdf %>%
filter(n_casual>casual_threshold),
tdf %>%
filter(n_member>member_threshold)
)
common_everyday_places <-
left_join(
common_places_during_bizday_rush_hours %>%
select (end_station_id),
idnamelatlng %>%
rename(end_station_id=id)
)
ggplot(tdf2 , aes(x=fct_reorder(end_station_name,n), y=n, fill=member_casual)) +
geom_bar(stat="identity") +
coord_flip()+
labs(title="Most popular destinations on a regular day",x=" ")
The difference between club members and casual riders is even more obvious. Just like during weekends, casual riders tend to prefer ‘leisure’ destinations. such as the Streeter Dr & Grand Ave, Michigan Ave & Oak St, DuSable Lake Shore Dr & Monroe Str, DuSable Lake Shore Dr & North Blvd.
model <- lm(n_casual ~ n_member, data = tdf %>% filter(n>2000))
r_squared <- summary(model)$r.squared
ggplot (tdf %>% filter(n>2000), aes(n_member, y=n_casual)) +
geom_rect(aes(xmin=0,xmax=member_threshold,ymin=casual_threshold,ymax=20000),fill="#FFEEEE",alpha=0.1)+
geom_rect(aes(xmin=member_threshold,xmax=12000,ymin=casual_threshold,ymax=20000),fill="#FFEEFF",alpha=0.1)+
geom_rect(aes(xmin=member_threshold,xmax=12000,ymin=0000,ymax=20000),fill="#EEEEFF",alpha=0.1)+
geom_point()+
# stat_cor(method = "pearson", label.x = 500, label.y = 15000)+
annotate("text", x = 1500, y = 15000, label = paste("R-squared =", round(r_squared, 2)))+
geom_text_repel(
data=tdf %>% filter(n_casual>casual_threshold | n_member>member_threshold), # Filter data first
aes(label=end_station_name, hjust=0), position = position_nudge(x = 100))+
annotate("text",x=10,y=20000-10,label="Popular\namong\ncasual riders",color="#FFAAAA", hjust=0, vjust=1)+
annotate("text",x=12000-10,y=20000-10,label="Popular among both casual riders\nand club members",color="#FFAAFF", hjust=1,vjust=1)+
annotate("text",x=12000-10,y=1000,label="Popular\namong club members",color="#AAAAFF", hjust=1, vjust=0)+
labs(title="Popular destinations on a regular day")
The correlation coefficient between the numbers of rides per station for different groups is low: R-squared=0.14.
The upper right quadrant of the plot is empty, indicating that there are no places that are equally attractive for both user groups.
Targeted Marketing Campaigns: Develop marketing campaigns that specifically target leisure cyclists, as they are majority of casual riders. Emphasize the fun and freedom in marketing campaign, because leisure cyclists often cycle for enjoyment and to explore the city.
Partnerships with Local Businesses: Partner with businesses in popular casual rider destinations along the Lake Michigan shoreline. These businesses could offer discounts or benefits to Cyclistic members, providing an additional incentive for casual riders to join.
Seasonal Promotions: Since casual riders are more active during warm weather and on weekends, consider offering seasonal promotions to encourage them to join as members during these peak times.
If stakeholders change their opinion and decide to target all-new customers, then they might improve the presence in periphery areas. As the members to casual ratio is higher in the periphery, it indicates a potential for market penetration. Consider increasing the availability of bikes or introducing special offers in these areas.
This study was fun. I learned a lot of tips and tricks. This R Markdown file is practically my very first cheatsheet for some common operations with data in R.