Author: Ray Han; with advice from Steven Jia
---
title: "NYC Yellow Cab Data Analysis & Visualization"
output:
flexdashboard::flex_dashboard:
orientation: rows
source_code: embed
---
Author: Ray Han;
with advice from Steven Jia
TLC Yellow Cab Data
=============
Row
-----------------------------------------------------------------------
### Glimpse of the Data
```{r warning = F, message = F, echo = F}
library(readr)
library(DT)
library(dplyr)
setwd("/Users/stevenjia93/Desktop/ColumbiaU/CU_Spring/DataVis/Project/Data")
df <- readr::read_csv("df.csv")
#----------- Remove Later
set.seed(1) # Remove Later
smalldf <- sample_frac(df, 0.01) # Remove
df <- smalldf
#----------- Remove Later
datatable(head(df, 100), options = list(
initComplete = JS(
"function(settings, json) {",
"$(this.api().table().header()).css({'background-color': '#000', 'color': '#fff'});",
"}"))
)
```
Row
-----------------------------------------------------------------------
### Use your time wisely as taxi drivers
```{r}
library(ggplot2)
library(dplyr)
stats1 <- df %>% group_by(pickup_hour) %>% summarise(mean(fare_per_min))
stats2 <- df %>% group_by(pickup_hour) %>% summarise(N = n())
stats <- left_join(stats1, stats2, by = "pickup_hour")
names(stats) <- c("pickup_hour", "mean_fare_per_min", "counts")
# install.packages("plotly")
library(plotly)
## Second axis
ay <- list(tickfont = list(color = "red"),
overlaying = "y",
side = "right",
title = "Avg fare/min")
plot_ly(stats, x =~ pickup_hour, y =~ counts,
name = "# of Trips" ,type = "bar") %>%
add_trace(y = ~ mean_fare_per_min, type = "scatter",
name = "Avg $ / min", mode = "line + markers", yaxis = "y2") %>%
layout(
title = "Average Fare per Minute ($ / min)",
xaxis = list(title = "Pickup Hour"),
yaxis = list(title = "Number of Trips"),
yaxis2 = ay
)
```
Clustering Analysis - Pickup Hotspot in Manhattan
=============
### Chart C
```{r}
library(RColorBrewer)
library(leaflet)
pal = colorFactor("Set1", domain = df$day)
color_weekday <- pal(df$day)
circle_popup <- paste("Weekday: ", df$day, "
",
"Total fare: ", df$total_amount,"USD","
",
"Trip distance: ", df$trip_distance,
"miles", "
",
"Number of passengers: ",
df$passenger_count)
leaflet(df) %>%
addTiles('http://{s}.tile.openstreetmap.de/tiles/osmde/{z}/{x}/{y}.png') %>%
setView(-73.985131, 40.758895, zoom = 10) %>%
addCircleMarkers(lng=~pickup_longitude, lat=~pickup_latitude,
color=color_weekday,
popup = circle_popup,
clusterOptions = markerClusterOptions())
```