Context

This notebook documents part of a data analysis I completed in the capstone experience for the Google Data Analytics Professional Certificate program on Coursera.

You can find the Github repository for my work here.

Analyze Phase

This phase involves identifying patterns, drawing conclusions and making data-driven decisions.

Load Libraries

I am using libraries from the tidyverse collection of R packages and supplementing with the knitr, RColorBrewer and sf libraries for table formatting, color palettes and manipulation of spatial data, i.e. to generate maps.

packages <- c("dplyr", "ggmap", "ggplot2", "ggridges", "ggthemes", "knitr", "lubridate", 
              "osmdata", "RColorBrewer", "sf", "stringr", "tidyr")

installed_packages <- packages %in% rownames(installed.packages())

if(any(installed_packages == FALSE)) {
  
  install.packages(packages[!installed_packages])
  
}

invisible(lapply(packages, library, character.only = TRUE))

Load Trip Data

Load the trip sample data.

load("C:/R/Packages/cyclistic/data/trip.rda")

The data frame contains a random selection of 250,000 trips from the 2022 data frame I created during the prepare and process phases of the project.

Color Palette

Specify a color-blind-friendly palette of eight colors for use with charts and visuals.

cbPalette <- c("#999999", "#E69F00", "#56B4E9", "#009E73", "#F0E442", "#0072B2", "#D55E00", "#CC79A7")

Exploratory Analysis

Proportion of Trips Taken by Customer Type

By knowing the proportion of trips taken by casual riders and members, I can identify which customer type dominates the usage. If casual riders significantly outnumber members, it suggests a higher potential for conversion, as there may be a larger pool of engaged and committed customers to appeal to.

If members already make up the majority of trips, prioritizing strategies to convert casual riders into members becomes crucial for sustained growth and revenue.

Analyzing the proportion of trips also helps in understanding how each customer type uses the service differently. This insight can be valuable in tailoring conversion strategies to address the specific needs, behaviors, and preferences of casual riders.

If the proportion of casual riders is low, it’s essential to identify potential barriers preventing them from becoming members. Analyzing the data can reveal whether it’s a lack of awareness, concerns about cost, or other factors hindering the conversion process.

Establish the proportion of trips taken by casual riders and members.

trips_by_member_type <- trip %>%
  group_by(member_type) %>%
  summarise(trip_count = n()) %>%
  mutate(percent = round(trip_count / sum(trip_count), 2)) %>%
  bind_rows(summarise(., across(where(is.numeric), sum),
                       across(where(is.character), ~ "Combined")))

kable(trips_by_member_type,
      col.names = c("Member Type", "Trip Count", "Percent"),
      caption = "Trips by Member Type",
      format.args = list(big.mark = ","),
      align = c("l", "r", "r"))
Trips by Member Type
Member Type Trip Count Percent
Casual 101,218 0.4
Member 148,782 0.6
Combined 250,000 1.0

Plot the proportions.

ggplot(trips_by_member_type[1:2,], aes(x = member_type, y = trip_count)) +
  geom_bar(stat = "identity", fill = cbPalette[2]) + 
  ylim(0, 155000) + 
  labs(title = "Proportion of Trips Taken by Member Type",
       subtitle = "Casual riders take four in every ten trips; this is a substantial customer presence.",
       x = "Member Type",
       y = "Trip Count") + 
  geom_text(aes(label = paste(percent * 100, "%", sep = "")), colour = "black", vjust = -0.35, size = 3) + 
  geom_text(aes(label = format(trip_count, big.mark = ",", scientific = FALSE)), colour = "black", vjust = 1.25, size = 3) + 
  scale_fill_manual(values = cbPalette)

ggsave(filename = "trips_by_member_type.png",
       path = "C:/R/Packages/cyclistic/inst/extdata/plots/",
       width = 7,
       height = 4,
       dpi = 600)

Observations

Four in every ten trips (40%) are taken by casual riders. The 40% proportion indicates a substantial presence of casual riders within the customer base. This suggests that a considerable portion of Cyclistic’s customers prefer a pay-as-you-go or occasional usage model rather than committing to a long-term membership.

Annual members, constituting 60% of the trips, are more actively engaged with the bike-sharing service. This high proportion could indicate that annual members use the service more consistently or for a broader range of purposes.

Opportunities

Some users may prefer the flexibility of occasional rides without the commitment of an annual membership, potentially using the service for specific purposes or as a sporadic means of transportation.

Understanding this proportion allows Cyclistic to strategically target casual riders with campaigns and incentives aimed at encouraging them to become members and enjoy the benefits of long-term commitment.

Considering the proportion of casual riders, Cyclistic might explore introducing flexible membership options or pricing plans that appeal to users who prefer occasional rides. This flexibility can enhance the service’s attractiveness to a broader audience.

Proportion of Trips by Customer Type and Month

Understanding how the proportion of trips fluctuates throughout the year provides insights into seasonal variations. This information can guide the timing of conversion campaigns, considering factors such as weather, holidays, or events that might influence customer behavior.

Establish the proportion of trips over time.

trips_by_member_type_and_month <- trip %>%
  mutate(month = month(start_date_time, label = TRUE, abbr = TRUE)) %>%
  group_by(month, member_type) %>%
  summarise(trip_count = n()) %>%
  mutate(percent = round(trip_count / sum(trip_count), 2))
## `summarise()` has grouped output by 'month'. You can override using the
## `.groups` argument.
kable(trips_by_member_type_and_month,
      col.names = c("Month", "Member Type", "Trip Count", "Percent"),
      caption = "Trips by Member Type and Month",
      format.args = list(big.mark = ","),
      align = c("l", "l", "r", "r"))
Trips by Member Type and Month
Month Member Type Trip Count Percent
Jan Casual 763 0.17
Jan Member 3,606 0.83
Feb Casual 846 0.17
Feb Member 4,007 0.83
Mar Casual 3,880 0.32
Mar Member 8,096 0.68
Apr Casual 5,260 0.34
Apr Member 10,040 0.66
May Casual 12,416 0.43
May Member 16,403 0.57
Jun Casual 17,115 0.47
Jun Member 19,364 0.53
Jul Casual 17,825 0.48
Jul Member 19,528 0.52
Aug Casual 15,842 0.44
Aug Member 19,787 0.56
Sep Casual 12,603 0.41
Sep Member 18,213 0.59
Oct Casual 8,682 0.37
Oct Member 14,505 0.63
Nov Casual 4,162 0.30
Nov Member 9,784 0.70
Dec Casual 1,824 0.25
Dec Member 5,449 0.75

Plot the proportions.

ggplot(trips_by_member_type_and_month, aes(x = month, y = trip_count)) +
  geom_bar(stat = "identity", fill = cbPalette[2]) + 
  ylim(-2000, 22000) + 
  labs(title = "Trips by Member Type and Month",
       subtitle = "Casual riders and members show levels of usage that is strongest in the summer months.",
       x = "Month",
       y = "Trip Count") + 
  facet_grid(rows = vars(member_type)) + 
  geom_text(aes(label = paste(percent * 100, "%", sep = "")), colour = "black", vjust = -0.35, size = 3) + 
  geom_text(aes(label = format(trip_count, big.mark = ",", scientific = FALSE)), colour = "black", vjust = 1.25, size = 3) + 
  scale_fill_manual(values = cbPalette)

ggsave(filename = "trips_by_member_type_and_month.png",
       path = "C:/R/Packages/cyclistic/inst/extdata/plots/",
       width = 7,
       height = 4,
       dpi = 600)

Observations

From January to December, both casual riders and members show varying levels of usage.

There seems to be a trend of increased usage, especially by members, during the warmer months (e.g., May to September), suggesting a possible seasonality effect where people are more inclined to use bike-sharing services in favorable weather.

Throughout the entire year, members consistently contribute to the majority of trips, with proportions ranging from 52% to 83%.

Casual ridership varies more compared to members, showing peaks and troughs throughout the year. The proportion of trips taken by casual riders ranges from 17% to 48%, suggesting fluctuations in the demand from this group.

Casual rider trips show a notable increase during the warmer months, reaching peak levels in June and July. This pattern suggests that casual riders are more active during the spring and summer seasons, possibly due to favorable weather conditions.

Member trips also exhibit a seasonal trend with higher counts during the warmer months, particularly in June, July, and August. Members, like casual riders, seem to be more engaged during the months with better weather.

The combined total of trips shows a clear seasonality, with a significant uptick in the spring and summer months. The months of June and July have the highest combined trip counts, indicating a peak in overall bike-sharing activity during these warmer periods.

Trips decrease during the winter months, particularly in December, with lower numbers for both casual and member riders. Colder temperatures, adverse weather conditions, and reduced outdoor activities during winter likely contribute to the decline in bike-sharing usage.

There is a noticeable decline in trips starting in September, marking the transition from summer to fall. This decline continues through the fall months, suggesting a seasonal shift in user behavior as temperatures decrease.

Opportunities

Months where member usage is rising or particularly high can serve as opportunities to focus on converting casual riders into members, as the overall engagement with the service is strong during these periods.

Note the seasonal patterns in casual and member trip counts. Months with higher casual rider proportions possibly indicate peak tourist seasons or specific events. Cyclistic can tailor conversion strategies to capitalize on these patterns.

Focus marketing campaigns, promotions, and outreach efforts on encouraging bike-sharing usage during the peak seasons. Highlight the benefits of biking in pleasant weather and promote seasonal events or initiatives to attract riders.

Consider implementing member retention strategies during the off-peak months to encourage continued engagement. This could involve special promotions, loyalty programs, or exclusive events to maintain member interest during colder seasons.

Develop strategies to mitigate the impact of winter on bike-sharing activity. This might include offering winter-specific promotions, providing weather-resistant gear, or adjusting services to accommodate changing user preferences during colder months.

Retention strategies might include collaborating with cold-weather gear brands to offer discounts or promotions for bike-sharing members. This could include discounts on gloves, hats, or other winter accessories, encouraging users to stay warm and comfortable while biking. Cyclistic might also consider winter riding challenges or winter social events to foster a sense of community.

Trips by Ride Type

Available ride types, whether classic or electric bicycles, can significantly influence the conversion of casual riders to members.

Electric bikes may offer a different and potentially more appealing experience for riders, especially those who are less accustomed to cycling or looking for a more effortless ride.

Electric bikes can be perceived as more accessible for a broader range of users, including those who may find traditional biking more strenuous.

Electric bikes can offer a faster and more convenient mode of transportation, particularly in hilly areas or for longer distances.

Do customers show any preference in ride type, i.e. classic bicycle versus electric? Determine the percent of rides taken using each ride type offered.

trips_by_ride_type <- trip %>%
  group_by(ride_type) %>%
  summarise(trip_count = n()) %>%
  mutate(percent = round(trip_count / sum(trip_count), 2)) %>%
  bind_rows(summarise(., across(where(is.numeric), sum),
                     across(where(is.character), ~ "Combined")))

kable(trips_by_ride_type,
      col.names = c("Ride Type", "Trip Count", "Percent"),
      caption = "Trips by Ride Type",
      format.args = list(big.mark = ","),
      align = c("l", "r", "r"))
Trips by Ride Type
Ride Type Trip Count Percent
Classic 150,296 0.60
Docked 8,507 0.03
Electric 91,197 0.36
Combined 250,000 0.99

Plot usage by ride type.

ggplot(trips_by_ride_type[1:3,], aes(x = ride_type, y = trip_count)) +
  geom_bar(stat = "identity", fill = cbPalette[2]) + 
  labs(title = "Trips by Ride Type",
       subtitle = "Customers show preference for classic bicycles, with significant interest in electric alternatives.",
       x = "Ride Type",
       y = "Trip Count") + 
  geom_text(aes(label = paste(percent * 100, "%", sep = "")), colour = "black", vjust = -0.35, size = 3) + 
  geom_text(aes(label = format(trip_count, big.mark = ",", scientific = FALSE)), colour = "black", vjust = 1.25, size = 3) + 
  scale_fill_manual(values = cbPalette)

ggsave(filename = "trips_by_ride_type.png",
       path = "C:/R/Packages/cyclistic/inst/extdata/plots/",
       width = 7,
       height = 4,
       dpi = 600)

Observations

Classic bikes have the highest trip count, constituting 60% of the total trips. This indicates a strong preference for traditional, non-electric bikes among users. The majority of riders seem to favor the classic biking experience.

Docked bikes represent only 3% of the total trips. This suggests that, compared to classic and electric bikes, the docked option is less popular among users. The low percentage may be influenced by factors such as accessibility or user preferences for dockless options.

Electric bikes contribute to 36% of the total trips, indicating a substantial user preference for this ride type. The popularity of electric bikes suggests that users value the convenience, speed, and ease of use associated with electric-assisted biking.

Opportunities

The high percentage of electric bike usage, combined with the prevalence of classic bikes, suggests that users appreciate having versatile options.

Electric bikes may be favored for certain scenarios, such as longer distances or hilly terrain, while classic bikes provide a more traditional biking experience.

Trips by Ride Type and Member Type

How does this preference vary when comparing customer types?

trips_by_member_and_ride_type_v1 <- trip %>%
  group_by(member_type, ride_type) %>%
  summarise(trip_count = n()) %>%
  pivot_wider(names_from = member_type, values_from = trip_count) %>%
  replace(is.na(.), 0) %>%
  bind_rows(summarise(., across(where(is.numeric), sum),
                   across(where(is.character), ~ "Combined"))) %>%
  mutate(total = rowSums(across(where(is.numeric))))
## `summarise()` has grouped output by 'member_type'. You can override using the
## `.groups` argument.
kable(trips_by_member_and_ride_type_v1,
      col.names = c("Ride Type", "Casual", "Member", "Total"),
      caption = "Trips by Member & Ride Type",
      format.args = list(big.mark = ","),
      align = c("l", "r", "r", "r"))
Trips by Member & Ride Type
Ride Type Casual Member Total
Classic 51,639 98,657 150,296
Docked 8,507 0 8,507
Electric 41,072 50,125 91,197
Combined 101,218 148,782 250,000

Plot ride type usage by customer type.

trips_by_member_and_ride_type_v2 <- trip %>%
  group_by(member_type, ride_type) %>%
  summarise(trip_count = n()) %>%
  mutate(percent = round(trip_count / sum(trip_count), 2))

ggplot(trips_by_member_and_ride_type_v2, aes(x = ride_type, y = trip_count)) +
  geom_bar(stat = "identity", fill = cbPalette[2]) + 
  labs(title = "Trips by Member Type & Ride Type",
     subtitle = "A greater proportion of casual riders prefer electric bicycles compared to members.",
     x = "Ride Type",
     y = "Trip Count") + 
  facet_grid(cols = vars(member_type)) + 
  geom_text(aes(label = paste(percent * 100, "%", sep = "")), colour = "black", vjust = -0.35, size = 3) + 
  geom_text(aes(label = format(trip_count, big.mark = ",", scientific = FALSE)), colour = "black", vjust = 1.25, size = 3) + 
  guides(fill=guide_legend(title="Ride Type")) + 
  scale_fill_manual(values = cbPalette)

ggsave(filename = "trips_by_member_and_ride_type.png",
       path = "C:/R/Packages/cyclistic/inst/extdata/plots/",
       width = 7,
       height = 4,
       dpi = 600)

Observations

Classic bikes are popular among both casual riders and members, with members contributing a higher proportion of trips. The majority of classic bike trips are taken by members, highlighting the enduring appeal of traditional biking for committed users.

Docked bikes are exclusively used by casual riders in this dataset, with no usage by members. This may indicate that docked bikes are more appealing to casual users or that the service availability for docked bikes is limited or specific to certain areas.

Electric bikes are utilized by both casual riders and members, with a similar distribution of trips between the two groups. This suggests that electric bikes have broad appeal across user segments, making them a popular and versatile choice.

Casual riders show a higher preference for electric bikes compared to members. While both customer types use electric bikes, casual riders contribute a larger share of trips on electric bikes within their total trip count.

Opportunities

Given these insights, Cyclistic could launch targeted promotional campaigns to encourage both casual riders and members to use electric bikes. Highlight the convenience, speed, and versatility of electric bikes, and offer discounts or incentives to boost their usage.

The company might also consider offering additional benefits or exclusive features for members who choose electric bikes. This could include priority access, special events, or discounted rates for electric bike usage, encouraging members to continue choosing this ride type.

Trips by Duration

Generate a summary of the trip duration column.

trips_by_duration <- trip %>%
  select(member_type, trip_duration_in_minutes) %>%
  group_by(interval = cut_width(trip_duration_in_minutes, width = 3, boundary = 0),
           member_type) %>%
  summarise(trip_count = n()) %>%
  pivot_wider(names_from = interval, values_from = trip_count) %>%
  bind_rows(summarise(., across(where(is.numeric), sum),
                 across(where(is.character), ~ "Combined"))) %>%
  mutate(total = rowSums(across(where(is.numeric))))
## `summarise()` has grouped output by 'interval'. You can override using the
## `.groups` argument.
kable(trips_by_duration,
      col.names = c("Member Type", "3-6", "6-9", "9-12", "12-15", "15-18", "18-21", 
                    "21-24", "24-27", "27-30", "30-33", "33-36", "36-39", "39-42", "Total"),
      caption = "Duration Frequency by Member Type & Interval",
      format.args = list(big.mark = ","),
      align = c("l", "r", "r", "r", "r", "r", "r", "r", "r", "r", "r", "r", "r", "r"))
Duration Frequency by Member Type & Interval
Member Type 3-6 6-9 9-12 12-15 15-18 18-21 21-24 24-27 27-30 30-33 33-36 36-39 39-42 Total
Casual 6,237 19,293 17,074 13,572 10,520 8,290 6,496 5,304 4,260 3,381 2,715 2,316 1,760 101,218
Member 15,308 38,756 28,362 19,306 13,502 9,328 6,826 5,090 3,947 2,920 2,261 1,833 1,343 148,782
Combined 21,545 58,049 45,436 32,878 24,022 17,618 13,322 10,394 8,207 6,301 4,976 4,149 3,103 250,000

Plot duration frequency.

ggplot(trip, aes(x = trip_duration_in_minutes, fill = member_type)) +
  geom_histogram(binwidth = 1, alpha = 1, position = "dodge") + 
  labs(title = "Trips by Member Type & Trip Duration",
     subtitle = "Members take more short-duration trips (less than 20 minutes) compared to casual riders.",
     x = "Trip Duration",
     y = "Trip Count") + 
  guides(fill=guide_legend(title="Member Type")) + 
  scale_fill_manual(values = cbPalette)

ggsave(filename = "trips_by_member_type_and_duration.png",
       path = "C:/R/Packages/cyclistic/inst/extdata/plots/",
       width = 7,
       height = 4,
       dpi = 600)

Plot duration by category of day.

ggplot(trip, aes(x = trip_duration_in_minutes, fill = category_of_day)) +
  geom_histogram(binwidth = 1, alpha = 1, position = "dodge") +
  facet_grid(rows = vars(member_type)) + 
  labs(title = "Trips by Member Type & Trip Duration",
   subtitle = "Most of the short-duration trips occur during the work week.",
   x = "Trip Duration",
   y = "Trip Count") + 
  guides(fill=guide_legend(title="Category of Day")) + 
  scale_fill_manual(values = cbPalette)

ggsave(filename = "trips_by_member_type_and_day_category.png",
       path = "C:/R/Packages/cyclistic/inst/extdata/plots/",
       width = 7,
       height = 4,
       dpi = 600)

Plot duration by day of week.

ggplot(trip, aes(x = trip_duration_in_minutes, fill = member_type)) +
  geom_histogram(binwidth = 1, alpha = 1, position = "dodge") +
  facet_grid(rows = vars(day_of_week)) + 
  labs(title = "Trips by Member Type & Trip Duration",
   subtitle = "Most of the short-duration trips occur during the work week.",
   x = "Trip Duration",
   y = "Trip Count") + 
  guides(fill=guide_legend(title="Member Type")) + 
  scale_fill_manual(values = cbPalette)

ggsave(filename = "trips_by_member_type_and_day_of_week.png",
       path = "C:/R/Packages/cyclistic/inst/extdata/plots/",
       width = 7,
       height = 4,
       dpi = 600)

Plot duration using kernal density plot.

ggplot(trip, aes(x = trip_duration_in_minutes, fill = member_type)) +
  geom_density(alpha = 0.5) +
    labs(title = "Trips by Member Type & Trip Duration",
    subtitle = "Members take more short-duration trips (less than 20 minutes) compared to casual riders.",
    x = "Trip Duration",
    y = "Density") + 
  guides(fill = guide_legend(title = "Member Type")) + 
  scale_fill_manual(values = cbPalette)

ggsave(filename = "trips_by_member_type_and_duration_density.png",
       path = "C:/R/Packages/cyclistic/inst/extdata/plots/",
       width = 7,
       height = 4,
       dpi = 600)

Observations

These chart shows that members have a higher volume of trips with a duration of less than twenty minutes. For trips with duration of twenty minutes or greater, casual riders and members have roughly the same volume.

The charts also demonstrate that most of the short-duration trips, regardless of customer type, are occurring during the work week versus weekends.

What might account for this difference?

Members may be using the bike-sharing service more efficiently for short, quick trips, such as commuting to nearby locations or running errands. The convenience and time-saving aspects of bike-sharing could be more appealing to members for shorter durations.

Members might be utilizing the service for daily commuting purposes within a close proximity, contributing to a higher volume of shorter trips. The predictability and routine nature of commuting could lead members to opt for quick rides.

Members, by virtue of their membership commitment, may feel more inclined to use the service frequently for various purposes, including short trips. The subscription model encourages regular usage among members.

The similarity in frequencies after twenty minutes could indicate that, for longer trips, both casual riders and members have comparable usage patterns. Longer trips may involve more leisurely rides or journeys to destinations farther away.

Beyond twenty minutes, the factors influencing bike-sharing usage may become more uniform between casual riders and members. Both customer types may share a similar interest in using bikes for leisure, exercise, or exploring areas that require a longer travel time.

Opportunities

Emphasize and promote the benefits of membership, especially for short trips, to encourage casual riders to consider becoming members. This could include highlighting cost savings, convenience, and additional perks for frequent users.

Tailor marketing strategies based on trip durations. For shorter trips, focus on promoting the efficiency and time-saving aspects of the service, while for longer trips, emphasize the leisure and exploration benefits.

Commutes Versus Recreation

Commute trips are often shorter because they typically involve traveling between a person’s home and workplace, which are likely to be relatively close. Recreational trips may involve exploring parks, neighborhoods, or other leisure destinations, which could lead to longer rides.

While it’s reasonable to assume that commute trips are generally shorter than recreational trips, the actual patterns can vary based on local factors and user preferences. Analyzing data specific to the bike-sharing service in a particular city or region would provide more accurate insights into trip lengths and user behavior.

Actual trip lengths for bike-sharing services can vary based on any of the following factors.

Demographics: Users of bike-sharing services can vary in age, fitness level, and cycling experience. Some users may be more comfortable with longer rides for recreation, while others may use bikes primarily for short commutes.

Urban Planning: The layout of a city and the availability of bike lanes and infrastructure can impact the convenience and safety of cycling. Cities with well-developed cycling infrastructure may see longer average trip lengths for both commuting and recreation.

Local Culture and Habits: Cultural factors and local habits may also play a role. In some areas, cycling could be more deeply ingrained in daily life, leading to longer rides for various purposes.

Weather Conditions: Weather can influence the willingness of individuals to use bike-sharing services. In inclement weather, people may prefer shorter rides for essential trips.

Bike Availability and Pricing Structure: The availability and pricing structure of bike-sharing services can impact user behavior. If bikes are readily available and priced affordably for short trips, users may be more inclined to use them for commuting.

Trips by Day of Week

Analyzing day-of-the-week patterns over time can reveal seasonal variations in bike-sharing usage over the short-term. Understanding peak days can help in designing targeted marketing campaigns and promotions.

Generate a summary of trips by day of week.

trips_by_member_type_and_day_of_week_v1 <- trip %>%
  group_by(day_of_week, member_type) %>%
  summarise(trip_count = n()) %>%
  bind_rows(summarise(., across(where(is.numeric), sum),
                      across(where(is.character), ~ "Combined"))) %>%
  pivot_wider(names_from = day_of_week, values_from = trip_count) %>%
  mutate(total = rowSums(across(where(is.numeric))))
## `summarise()` has grouped output by 'day_of_week'. You can override using the
## `.groups` argument.
kable(trips_by_member_type_and_day_of_week_v1,
      col.names = c("Member Type", "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Total"),
      caption = "Trips by Member Type & Day of Week",
      format.args = list(big.mark = ","),
      align = c("l", "r", "r", "r", "r", "r", "r", "r", "r"))
Trips by Member Type & Day of Week
Member Type Sun Mon Tue Wed Thu Fri Sat Total
Casual 17,136 11,843 11,335 11,841 13,348 14,514 21,201 101,218
Member 17,183 20,834 23,634 23,368 23,786 20,461 19,516 148,782
Combined 34,319 32,677 34,969 35,209 37,134 34,975 40,717 250,000

Plot trips by day of week.

trips_by_member_type_and_day_of_week_v2 <- trip %>%
  group_by(day_of_week, member_type) %>%
  summarise(trip_count = n()) %>%
  mutate(percent = round(trip_count / sum(trip_count), 2))

ggplot(trips_by_member_type_and_day_of_week_v2, aes(x = day_of_week, y = trip_count, fill = member_type)) +
  geom_bar(stat = "identity") + 
  facet_grid(rows = vars(member_type)) + 
  ylim(0, 25000) +
  labs(title = "Trips by Member Type & Day of Week",
       subtitle = "While overall trips peak on Saturdays; for members, trips peak in mid-week.",
       x = "Day of Week",
       y = "Trip Count") + 
  guides(fill = guide_legend(title = "Member Type")) + 
  geom_text(aes(label = paste(percent * 100, "%", sep = "")), colour = "black", vjust = -0.35, size = 3) + 
  geom_text(aes(label = format(trip_count, big.mark = ",", scientific = FALSE)), colour = "black", vjust = 1.25, size = 3) + 
  scale_fill_manual(values = cbPalette)

ggsave(filename = "trips_by_member_type_and_day_of_week.png",
       path = "C:/R/Packages/cyclistic/inst/extdata/plots/",
       width = 7,
       height = 4,
       dpi = 600)

Observations

Casual riders show a notable increase in trip counts on Saturdays, indicating that weekends are the peak period for this customer type. Saturday has the highest trip count among all days.

Weekday usage for casual riders remains relatively consistent, with Monday through Thursday showing similar trip counts. While there is a slight increase on Friday, the significant peak is observed on Saturday.

Mondays tend to have the lowest trip count for casual riders. This could be attributed to a slower start to the week, with users potentially engaging less in bike-sharing activities.

Members exhibit a consistent pattern of higher trip counts on weekdays (Monday through Friday). Weekdays, particularly Tuesday through Thursday, have the highest trip counts for members.

Members show a decline in trip counts on Saturdays and Sundays, with Saturday having the lowest trip count among all days. This suggests that members are less active in bike-sharing activities during the weekends.

Opportunities

Tailor communication strategies based on the preferred usage days of each customer type. Highlighting specific benefits, promotions, or events during days with lower trip counts for each group can be more effective.

Trips by Hour of Day

Analyzing trips by the hour of the day offers additional granularity and insights into the temporal patterns of bike-sharing usage.

Understand the proportion of trips with the same start and end hour to inform the choice between using the starting hour or ending hour as a representative data point for the time of a trip.

trips_by_start_end_proportion <- trip %>%
  group_by(start_end_category) %>%
  summarise(trip_count = n()) %>%
  mutate(percent = round(trip_count / sum(trip_count), 2)) %>%
  bind_rows(summarise(., across(where(is.numeric), sum),
                      across(where(is.character), ~ "Combined")))

kable(trips_by_start_end_proportion,
      col.names = c("Category", "Trip Count", "Percent"),
      caption = "Trips by Start & End Hours",
      format.args = list(big.mark = ","),
      align = c("l", "r", "r"))
Trips by Start & End Hours
Category Trip Count Percent
Different 58,905 0.24
Same 191,095 0.76
Combined 250,000 1.00

Trips with the same start and end hour are the dominant category, and analyzing this group could provide valuable insights into the overall usage patterns during the entire duration of a trip.

The second category, although smaller, could be interesting to explore. Trips where the starting and ending hours are different might indicate instances where users begin their journey at one time and conclude it later. This could be due to factors like extended breaks or intermediate stops during a trip.

Analyze patterns within the second category might identify any specific trends or behaviors. For example, users may start a trip in the morning and finish it in the evening, suggesting a day-long bike-sharing activity.

Conducting a combined analysis that looks at both starting and ending hours should generate a comprehensive understanding of the temporal aspects of bike-sharing trips.

Generate a summary of trips by hour of day retaining the hour type for combined analysis.

The following code segment creates a data frame to represent hours of the day. It defines a function to count active trips for each hour, considering the start and end hours of trips. The code then applies this function to generate a new data frame with counts of active trips for each hour.

The goal is to analyze and summarize the number of active trips during different hours of the day based on the trip start and end times, accounting for trips that overlap multiple hour intervals.

hours <- 0:23

hourly_counts <- data.frame(hour_of_day = hours)

count_active_trips <- function(current_hour, start_hour, end_hour) {
  
  sum(start_hour <= current_hour & end_hour >= current_hour)

}

hourly_counts <- hourly_counts %>%
  rowwise() %>%
  mutate(active_trip_count = count_active_trips(hour_of_day, trip$start_hour_of_day, trip$end_hour_of_day))

kable(hourly_counts,
      col.names = c("Hour", "Active Trip Count"),
      caption = "Active Trips by Hour Interval",
      format.args = list(big.mark = ","),
      align = c("l", "r"))
Active Trips by Hour Interval
Hour Active Trip Count
0 3,365
1 2,758
2 1,693
3 964
4 738
5 1,897
6 5,843
7 11,688
8 15,092
9 11,664
10 11,620
11 14,493
12 17,358
13 17,924
14 18,711
15 21,402
16 27,080
17 32,761
18 28,857
19 21,252
20 14,872
21 11,686
22 9,566
23 5,621

Then plot the summary.

ggplot(hourly_counts, aes(x = hour_of_day, y = active_trip_count)) +
  geom_bar(stat = "identity", fill = cbPalette[2]) + 
  geom_smooth(se = FALSE, colour = cbPalette[1]) +
  labs(title = "Active Trips by Hour Interval",
   subtitle = "Trips peak between the hours of 7:00-9:00 am and 4:00-6:00 pm.",
   x = "Hour of Day",
   y = "Active Trip Count") + 
  # guides(fill=guide_legend(title="Hour Type")) + 
  scale_fill_manual(values = cbPalette)

ggsave(filename = "trips_by_hour_interval.png",
       path = "C:/R/Packages/cyclistic/inst/extdata/plots/",
       width = 7,
       height = 4,
       dpi = 600)

Plot trips by hour of day and day of week.

start_trips <- trip %>%
  group_by(start_hour_of_day, day_of_week, member_type) %>%
  summarise(trip_count = n()) %>%
  mutate(type = "Start") %>%
  rename(hour_of_day = start_hour_of_day)

end_trips <- trip %>%
  group_by(end_hour_of_day, day_of_week, member_type) %>%
  summarise(trip_count = n()) %>%
  mutate(type = "End") %>%
  rename(hour_of_day = end_hour_of_day)

trips_by_hour_v2 <- rbind(start_trips, end_trips) %>%
  select(-type)

ggplot(trips_by_hour_v2, aes(x = hour_of_day, y = trip_count, fill = member_type)) +
  geom_bar(stat = "identity") +
  facet_grid(rows = vars(day_of_week)) + 
  labs(title = "Trips by Member Type & Day of Week",
    subtitle = "Daily and hourly patterns highlight commute and recreation dynamics.",
    x = "Hour of Day",
    y = "Trip Count") + 
  guides(fill=guide_legend(title = "Member Type")) + 
  scale_fill_manual(values = cbPalette)

ggsave(filename = "trips_by_hour_of_day.png",
       path = "C:/R/Packages/cyclistic/inst/extdata/plots/",
       width = 7,
       height = 4,
       dpi = 600)

Observations

The peak hours for bike-sharing usage across all days are typically between 7 AM and 9 AM, and 4 PM and 6 PM. These periods coincide with typical commuting times, suggesting that a significant portion of trips is related to daily commuting activities.

There is a clear pattern of increasing active trip counts in the morning hours, peaking around hours 8 to 9, followed by a decrease in the afternoon. The evening hours (16 to 17) exhibit another peak, likely associated with the evening commute.

Hours 10 to 15, representing midday, maintain relatively stable and moderate levels of active trips.

Weekdays show a distinct pattern with two peaks corresponding to morning and evening commuting hours. On weekends, the usage pattern is more evenly distributed throughout the day, with a single peak in the afternoon.

Opportunities

Highlight member benefits during peak commuting hours to encourage membership subscriptions. Memberships with additional benefits during rush hours could incentivize regular users.

During the peak morning hours (7 to 9), there’s a significant influx of users, likely related to the morning commute. Consider offering incentives, promotions, or discounts during these hours to encourage more casual riders to use the bike-sharing service for their commute.

Leverage the peak in active trip counts during the late afternoon (16 to 17) to target casual riders who may be commuting home. Promotions like discounted rides, referral programs, or membership trials during these hours could entice more users.

Geographic Density Analysis

To get a sense of how the trip data relates to geographic of the city, let’s look at dot density maps.

To start, create a bounding box for Chicago to get geographic boundaries in latitude and longitude. Print the coordinates.

bb <- getbb("Chicago, IL"); bb
##         min       max
## x -87.94009 -87.52408
## y  41.64453  42.02304

The variable ‘x’ represents longitude, and variable ‘y’ represents latitude.

Use these coordinates to setup a simple feature geometric object for visuals (i.e. maps).

csf <- coord_sf(xlim = c(bb[1, 1], bb[2, 1]), ylim = c(bb[1, 2], bb[2, 2]), expand = TRUE)

Chicago Data Portal

The Chicago Data Portal enables analysts to find city data and create maps and graphs about the city. Users can freely download the data for their analyses.

I downloaded shape files from the portal to create maps of Cyclistic bike-sharing stations, visualize station usage, and understand the relationship between stations and features of the city, i.e. communities, parks, and landmarks.

I downloaded the corresponding shape files and use them to generate maps. These shape files contain boundaries of communities, parks, landmarks (both local and national), and bike routes within the city. I also include a shape file for the boundaries of Chicago’s central business district.

communities <- st_read("C:/R/Packages/cyclistic/inst/extdata/chicago/communities/geo_export_communities.shp")
## Reading layer `geo_export_communities' from data source 
##   `C:\R\Packages\cyclistic\inst\extdata\chicago\communities\geo_export_communities.shp' 
##   using driver `ESRI Shapefile'
## Simple feature collection with 77 features and 9 fields
## Geometry type: MULTIPOLYGON
## Dimension:     XY
## Bounding box:  xmin: -87.94011 ymin: 41.64454 xmax: -87.52414 ymax: 42.02304
## Geodetic CRS:  WGS84(DD)
parks <- st_read("C:/R/Packages/cyclistic/inst/extdata/chicago/parks/geo_export_parks.shp")
## Reading layer `geo_export_parks' from data source 
##   `C:\R\Packages\cyclistic\inst\extdata\chicago\parks\geo_export_parks.shp' 
##   using driver `ESRI Shapefile'
## Simple feature collection with 617 features and 80 fields
## Geometry type: MULTIPOLYGON
## Dimension:     XY
## Bounding box:  xmin: -87.83901 ymin: 41.64466 xmax: -87.52444 ymax: 42.02299
## Geodetic CRS:  WGS84(DD)
landmarks <- st_read("C:/R/Packages/cyclistic/inst/extdata/chicago/landmarks/geo_export_landmarks.shp")
## Reading layer `geo_export_landmarks' from data source 
##   `C:\R\Packages\cyclistic\inst\extdata\chicago\landmarks\geo_export_landmarks.shp' 
##   using driver `ESRI Shapefile'
## Simple feature collection with 317 features and 5 fields
## Geometry type: MULTIPOLYGON
## Dimension:     XY
## Bounding box:  xmin: 1123286 ymin: 1822830 xmax: 1205091 ymax: 1949374
## Projected CRS: NAD83 / Illinois East (ftUS)
national_landmarks <- st_read("C:/R/Packages/cyclistic/inst/extdata/chicago/national/geo_export_national_landmarks.shp")
## Reading layer `geo_export_national_landmarks' from data source 
##   `C:\R\Packages\cyclistic\inst\extdata\chicago\national\geo_export_national_landmarks.shp' 
##   using driver `ESRI Shapefile'
## Simple feature collection with 318 features and 6 fields
## Geometry type: MULTIPOLYGON
## Dimension:     XY
## Bounding box:  xmin: 1124289 ymin: 1828318 xmax: 1205092 ymax: 1949374
## Projected CRS: NAD83 / Illinois East (ftUS)
routes <- st_read("C:/R/Packages/cyclistic/inst/extdata/chicago/routes/geo_export_bike_routes.shp")
## Reading layer `geo_export_bike_routes' from data source 
##   `C:\R\Packages\cyclistic\inst\extdata\chicago\routes\geo_export_bike_routes.shp' 
##   using driver `ESRI Shapefile'
## Simple feature collection with 953 features and 10 fields
## Geometry type: MULTILINESTRING
## Dimension:     XY
## Bounding box:  xmin: -87.81235 ymin: 41.64946 xmax: -87.52455 ymax: 42.02255
## Geodetic CRS:  WGS84(DD)
business <- st_read("C:/R/Packages/cyclistic/inst/extdata/chicago/business/geo_export_business_district.shp")
## Reading layer `geo_export_business_district' from data source 
##   `C:\R\Packages\cyclistic\inst\extdata\chicago\business\geo_export_business_district.shp' 
##   using driver `ESRI Shapefile'
## Simple feature collection with 1 feature and 7 fields
## Geometry type: POLYGON
## Dimension:     XY
## Bounding box:  xmin: -87.64791 ymin: 41.86703 xmax: -87.59852 ymax: 41.90414
## Geodetic CRS:  WGS84(DD)

Geographic Density of Trips

Trip Starts and Ends

Start by generating a data frame that contains the trip count for each starting and ending station in descending order of count. Include relative frequency for each station.

trip_starts <- trip %>%
  group_by(start_station_name, start_longitude, start_latitude) %>%
  summarise(trip_count = n()) %>%
  arrange(desc(trip_count)) %>%
  ungroup() %>%
  mutate(type = "Start",
         percent = round(trip_count / sum(trip_count), 2)) %>%
  rename(station_name = start_station_name,
         longitude = start_longitude,
         latitude = start_latitude)

trip_ends <- trip %>%
  group_by(end_station_name, end_longitude, end_latitude) %>%
  summarise(trip_count = n()) %>%
  arrange(desc(trip_count)) %>%
  ungroup() %>%
  mutate(type = "End",
         percent = round(trip_count / sum(trip_count), 2)) %>%
  rename(station_name = end_station_name,
         longitude = end_longitude,
         latitude = end_latitude)

trip_starts_and_ends <- rbind(trip_starts, trip_ends)

Plot trip starts and ends.

ggplot() +
  geom_sf(data = communities, fill = "grey", alpha = 0.1) +
  geom_point(data = trip_starts_and_ends,
             size = 0.5,
             aes(x = longitude, 
                 y = latitude,
                 colour = "#E69F00")) + 
  facet_grid(~factor(type, levels=c("Start", "End"))) +
  scale_color_identity() +
  csf + 
  geom_sf(data = business, fill = "grey", alpha = 0.4) +
  labs(title = "Geographic Density of Trip Starts & Ends",
       subtitle = "Trips are concentrated in and extend from Chicago's central business district.",
       x = "Longitude",
       y = "Latitude")

ggsave(filename = "trip_starts_and_ends.png",
       path = "C:/R/Packages/cyclistic/inst/extdata/plots/",
       width = 7,
       height = 4,
       dpi = 600)

Observations

The concentration of bike-sharing activity in and around Chicago’s central Business District (CBD) suggests that the bike-sharing service is heavily utilized in areas where people work, conduct business, or engage in commercial and recreational activities.

Many trips could be associated with commuting to and from workplaces in the CBD, or users may be utilizing bikes for business-related purposes, such as meetings or appointments. The CBD may also serve as a hub for recreational activities and tourist attractions.

The widespread distribution of trip starts and ends throughout the entire Chicago area indicates that bike-sharing is not limited to a specific region but is accessible and used across various neighborhoods and communities.

Trips starting and ending in diverse locations suggest that bike-sharing is not solely a commuting service. Residents in different neighborhoods may use it for local transportation. Bike-sharing might be popular among tourists exploring different parts of the city. The service may be well-integrated into the city’s transportation network, facilitating point-to-point travel.

Opportunities

The combination of concentrated activity in the CBD and dispersed trips across the city suggests the bike-sharing service caters to diverse needs, including commuting, recreation, and local transportation.

Bike-sharing can serve as a solution for last-mile connectivity. Identify transportation hubs, such as train stations or bus stops, and strategically place bike-sharing stations to facilitate seamless travel for commuters completing the last leg of their journey.

If trips are dispersed throughout the city, consider targeting tourism hubs and popular attractions. Promote bike-sharing as a convenient and eco-friendly way for tourists to explore the city’s diverse neighborhoods and landmarks.

Chicago Geography

The presence of a critical mass of bike routes throughout Chicago, combined with local and national landmarks, presents various observations and opportunities for enhancing the city’s bike-sharing system:

Bike Routes

Generate summary of bike routes.

route_summary <- as.data.frame(routes) %>%
  select(displayrou, mi_ctrline) %>%
  mutate(displayrou = str_to_title(displayrou)) %>%
  group_by(displayrou) %>%
  summarise(count = n(),
            total_miles = round(sum(mi_ctrline), 0)) %>%
  arrange(desc(total_miles)) %>%
  bind_rows(summarise(., across(where(is.numeric), sum),
                      across(where(is.character), ~ "Combined")))

kable(route_summary,
      col.names = c("Route Type", "Route Count", "Total Miles"),
      caption = "Summary of Chicago Bike Routes",
      format.args = list(big.mark = ","),
      align = c("l", "r", "r"))
Summary of Chicago Bike Routes
Route Type Route Count Total Miles
Bike Lane 335 126
Buffered Bike Lane 261 116
Shared-Lane 130 50
Neighborhood Greenway 112 39
Protected Bike Lane 115 38
Combined 953 369

Chicago has a total of 953 bike routes throughout the city, covering 369 miles based on measurement of route center lines.

Plot bike routes to visualize the network of routes.

ggplot() +
  geom_sf(data = communities, fill = "white") + 
  geom_sf(data = routes, color = "#E69F00") + 
  labs(title = "Chicago Bike Routes",
    x = "Longitude",
    y = "Latitude") + 
  scale_fill_manual(values = cbPalette) +
  theme(plot.title = element_text(hjust = 0.5))

ggsave(filename = "bike_routes.png",
       path = "C:/R/Packages/cyclistic/inst/extdata/plots/",
       width = 6,
       height = 7,
       dpi = 600)

The extensive network of bike routes indicates a high level of connectivity, making it feasible for users to navigate through various parts of the city using bikes.

The well-connected infrastructure contributes to the attractiveness of bike-sharing, as users can travel efficiently and safely.

Parks

Chicago has 8,868.752 acres of park land throughout the city that support a broad range of recreational activities.

Plot parks.

ggplot() +
  geom_sf(data = communities, fill = "white") + 
  geom_sf(data = parks, fill = "#E69F00") + 
  labs(title = "Chicago Parks & Recreation Areas",
    x = "Longitude",
    y = "Latitude") + 
  scale_fill_manual(values = cbPalette) +
  theme(plot.title = element_text(hjust = 0.5))

ggsave(filename = "parks.png",
       path = "C:/R/Packages/cyclistic/inst/extdata/plots/",
       width = 6,
       height = 7,
       dpi = 600)

Bike routes that traverse parks often offer scenic and enjoyable paths. Cyclists can experience a more pleasant and aesthetically pleasing journey, making biking a more enjoyable and attractive mode of transportation.

Landmarks

Chicago has 317 local landmarks and 318 national landmarks throughout the city.

Plot landmarks.

ggplot() +
  geom_sf(data = communities, fill = "white") + 
  geom_sf(data = landmarks, fill = "#E69F00") + 
    geom_sf(data = national_landmarks, fill = "#E69F00") + 
  labs(title = "Chicago Landmarks",
    x = "Longitude",
    y = "Latitude") + 
  scale_fill_manual(values = cbPalette) +
  theme(plot.title = element_text(hjust = 0.5))

ggsave(filename = "landmarks.png",
       path = "C:/R/Packages/cyclistic/inst/extdata/plots/",
       width = 6,
       height = 7,
       dpi = 600)

The concentration of landmarks and national landmarks suggests focal points of interest and cultural significance.

These central locations create opportunities for bike-sharing services to cater to tourists, residents, and event-goers who may want convenient and sustainable transportation options to explore these landmarks.

Landmarks and national landmarks often attract tourists, creating potential opportunities for bike-sharing services. Bike-sharing can be promoted as a tourist-friendly transportation mode, allowing visitors to explore the city at their own pace, visit attractions, and experience the local culture.

Observations

Collaborations with museums, theaters, and other cultural venues can boost awareness and usage, creating a symbiotic relationship between bike-sharing and cultural experiences.

Opportunities

Establish partnerships with cultural institutions near landmarks for joint promotional activities.

Extend bike-sharing services to neighborhoods surrounding landmarks to capture both tourist and local resident markets.

Explore collaborations with tourism services to offer bundled packages that include bike-sharing along with guided tours or city passes.

Limitations & Future Analysis Opportunities

While the trips data was useful for generating insights into customer usage of the bike-sharing service, some enhancements would be beneficial to future analyses.

Conduct surveys or gather user feedback to understand the motivations and preferences of both casual riders and members. Insights into why members prefer shorter trips and how casual riders perceive longer rides can inform targeted strategies.

Understand usage of residents versus non-residents will help understand the impact of tourism on customer activity and help generate a more realistic assessment of casual user conversion opportunity.

Data on bicycle availability would enable Cyclistic to assess how availability impacts usage patterns.

Analysis of pricing and how it influences customer behavior, e.g. trip duration, usage over time, etc.

Analysis of customer demographics and how this influences usage, i.e. age, fitness level, cycling experience.

Mode of transportation integration, i.e. how are casual riders and members integrating the service with other modes of transportation? Is there a “last mile” dynamic present in customer behavior, i.e. using the bike-sharing service for the final leg of a journey, typically from a transportation hub (like a train or bus station) to the final destination, which might be just a short distance away. This data could shed additional light on why there are so many short-duration trips in the data.

Next Steps

The next step in this project is to share the data for stakeholder review and action.