1. Distribution of Subway Ridership


-The frequency distribution of daily subway ridership numbers and reveals how often certain ridership levels occurred. You can see if ridership was consistently high, low, or varied widely.

2. Comparison of Bus vs Subway Ridership Over Time


-This Multi-line Time Series graph shows the ridership trends for both subways and buses plotted over time on the same graph. It visually compares how subway and bus usage changed on the same days — helpful to see which mode recovered faster or was more affected by external events.

3. Boxplot of Subway Ridership by Month


-This boxplot chart shows the Monthly distribution of subway ridership (median, quartiles, outliers and shows seasonal or monthly patterns. For example, summer months might have lower ridership due to vacations, or you might see spikes in certain months

4. Bridges and Tunnels Traffic Over Time


-This line chart shows the total traffic volume across NYC bridges and tunnels over time. It is very useful for comparing traffic flow trends to public transit usage. You might observe shifts between driving and transit during specific periods.

5. Bridge & Tunnel Traffic Distribution


-This density plot chart shows the shape of the distribution of daily vehicle traffic.It helps understand the concentration of typical traffic levels (e.g., most days fall around X number of vehicles). It smooths out the data unlike histograms.

6. Staten Island Railway Ridership Trend


-This Histogram chart shows the distribution of daily ridership on the Staten Island Railway (SIR), because while not as heavily used as subways/buses, it’s important to understand SIR ridership patterns for service planning and equity.

7. Scatter Plot – Subway vs Bus Ridership


-This Scatter Plot chart shows the correlation between subway and bus ridership on the same day and shows whether increases or decreases in subway ridership coincide with similar changes in bus usage — possibly suggesting complementarity or substitution.

8. Bar Chart – Average Ridership by Mode


-This bar chart shows the mean daily ridership across all days in the dataset for each transit mode (Subway, Bus, SIR).It gives a quick snapshot of relative usage — how heavily each mode is used on average — useful for capacity planning and resource allocation.

---
title: "Bamba Midterm"
author: "Bamba"
output: 
 flexdashboard::flex_dashboard:
   storyboard: true
   social: menu
   source: embed
---

```{r setup, include=FALSE}

library(tidyverse)
library(lubridate)
library(ggplot2)
library(plotly)

# Read the dataset
mta <- read_csv("MTA_Daily_Ridership.csv")

# Convert Date and extract Month
mta <- mta %>%
  mutate(Date = mdy(Date)) %>%
  mutate(Month = month(Date, label = TRUE))
mta_long <- mta %>%
  select(Date, `Subways: Total Estimated Ridership`, `Buses: Total Estimated Ridership`) %>%
  pivot_longer(cols = -Date, names_to = "Mode", values_to = "Ridership")
knitr::opts_chunk$set(echo = TRUE)
```

### 1. Distribution of Subway Ridership

```{r echo=FALSE}
ggplotly(
  ggplot(mta, aes(x = `Subways: Total Estimated Ridership`)) +
    geom_histogram(binwidth = 500000, fill = "steelblue", color = "black", alpha = 0.7) +
    labs(
      title = "Distribution of Subway Ridership",
      x = "Total Estimated Subway Ridership",
      y = "Frequency (Number of Days)"
    ) +
    theme_minimal()
)
```
  ***
-The frequency distribution of daily subway ridership numbers and reveals how often certain ridership levels occurred. You can see if ridership was consistently high, low, or varied widely.


### 2. Comparison of Bus vs Subway Ridership Over Time 

```{r echo=FALSE}
ggplotly(
ggplot(mta_long, aes(x = Date, y = Ridership, color = Mode)) +
    geom_line() +
    labs(title = "Bus vs Subway Ridership Over Time", x = "Date", y = "Ridership") +
    theme_minimal()

)
```
  ***
-This Multi-line Time Series graph shows the ridership trends for both subways and buses plotted over time on the same graph. It visually compares how subway and bus usage changed on the same days — helpful to see which mode recovered faster or was more affected by external events.


### 3. Boxplot of Subway Ridership by Month

```{r echo=FALSE}
ggplotly(
ggplot(mta, aes(x = , y = `Subways: Total Estimated Ridership`)) +
  geom_boxplot(fill = "lightblue") +
  labs(title = "Subway Ridership by Month", x = "Month", y = "Riders") +
  theme_minimal()
)
```
  ***
-This boxplot chart shows the Monthly distribution of subway ridership (median, quartiles, outliers and shows seasonal or monthly patterns. For example, summer months might have lower ridership due to vacations, or you might see spikes in certain months

### 4. Bridges and Tunnels Traffic Over Time

```{r echo=FALSE}
ggplotly(
  ggplot(mta, aes(x = Date, y = `Bridges and Tunnels: Total Traffic`)) +
    geom_line(color = "darkgreen") +
    labs(title = "Bridge & Tunnel Traffic Over Time", x = "Date", y = "Vehicles") +
    theme_minimal()
)
```
  ***
-This line chart shows the total traffic volume across NYC bridges and tunnels over time. It is very useful for comparing traffic flow trends to public transit usage. You might observe shifts between driving and transit during specific periods.


### 5. Bridge & Tunnel Traffic Distribution


```{r echo=FALSE}
ggplotly(
  ggplot(mta, aes(x = `Bridges and Tunnels: Total Traffic`)) +
    geom_density(fill = "darkgreen", alpha = 0.5) +
    labs(title = "Bridge & Tunnel Traffic Distribution", x = "Vehicles", y = "Density") +
    theme_minimal()
)
```
  ***
-This density plot chart shows the shape of the distribution of daily vehicle traffic.It helps understand the concentration of typical traffic levels (e.g., most days fall around X number of vehicles). It smooths out the data unlike histograms.


### 6. Staten Island Railway Ridership Trend

```{r echo=FALSE}
ggplotly(
  ggplot(mta, aes(x = `Staten Island Railway: Total Estimated Ridership`)) +
    geom_histogram(binwidth = 1000, fill = "purple", color = "black", alpha = 0.7) +
    labs(title = "Staten Island Railway Ridership", x = "Ridership", y = "Count") +
    theme_minimal()
)
```
  ***
-This Histogram chart shows the distribution of daily ridership on the Staten Island Railway (SIR), because while not as heavily used as subways/buses, it's important to understand SIR ridership patterns for service planning and equity.


### 7. Scatter Plot – Subway vs Bus Ridership

```{r echo=FALSE}
ggplotly(
  ggplot(mta, aes(x = `Subways: Total Estimated Ridership`,
                  y = `Buses: Total Estimated Ridership`)) +
    geom_point(alpha = 0.5, color = "tomato") +
    labs(
      title = "Subway vs Bus Ridership",
      x = "Subway Riders",
      y = "Bus Riders"
    ) +
    theme_minimal()
)
```
  ***
-This Scatter Plot chart shows the correlation between subway and bus ridership on the same day and shows whether increases or decreases in subway ridership coincide with similar changes in bus usage — possibly suggesting complementarity or substitution.


### 8. Bar Chart – Average Ridership by Mode

```{r echo=FALSE}
mta_avg <- mta %>%
  summarize(
    Subway = mean(`Subways: Total Estimated Ridership`, na.rm = TRUE),
    Bus = mean(`Buses: Total Estimated Ridership`, na.rm = TRUE),
    SIR = mean(`Staten Island Railway: Total Estimated Ridership`, na.rm = TRUE)
  ) %>%
  pivot_longer(cols = everything(), names_to = "Mode", values_to = "Avg_Ridership")
ggplotly(  
ggplot(mta_avg, aes(x = Mode, y = Avg_Ridership, fill = Mode)) +
    geom_bar(stat = "identity") +
    labs(
      title = "Average Daily Ridership by Mode",
      x = "Transit Mode",
      y = "Avg Riders"
    ) +
    theme_minimal()
)
```
  ***
-This bar chart shows the mean daily ridership across all days in the dataset for each transit mode (Subway, Bus, SIR).It gives a quick snapshot of relative usage — how heavily each mode is used on average — useful for capacity planning and resource allocation.