generated from jtr13/quarto-edav-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
results.qmd
116 lines (92 loc) · 2.62 KB
/
results.qmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# Results
```{r}
#| echo: false
#| message: false
#| warning: false
library(tidyverse)
library(arrow)
library(scales)
library(RColorBrewer)
library(patchwork)
library(lubridate)
library(timeDate)
library(ggrepel)
# Use like: scale_y_continuous(labels = millions) +
millions <- function(x) {
ifelse(x == 0, "0", label_comma(scale = 1e-6, suffix = "M")(x))
}
# Use like: scale_y_continuous(labels = thousands) +
thousands <- function(x) {
ifelse(x == 0, "0", label_comma(scale = 1e-3, suffix = "K")(x))
}
double_scale <- function(x) {
ifelse(x >= 1000, paste0(x / 1000, "K"), as.character(x))
}
# Use in mutate: mutate(foo= standardize(bar))
standardize <- function(x) {
(x - mean(x, na.rm = TRUE)) / sd(x, na.rm = TRUE)
}
base_color <- brewer.pal(n = 3, name = "Set2")[1]
secondary_color <- brewer.pal(n=3, name = "Set2")[2]
rain_color <- brewer.pal(n=3, name = "Set2")[3]
classic <- theme_set(theme_minimal())
temp_label <- "Temperature (°C)"
df <- read_parquet("data/complete_weather_and_taxi_data.parquet")
```
```{r}
#| echo: false
# Add a month_abbr column.
df <- df |>
mutate(month_abbr = factor(month.abb[month], levels = month.abb))
```
## A New Normal: How the COVID-19 Pandemic Reshaped Taxi Ridership Patterns
{{< include sections/3/1_dealing_with_the_pandemic.qmd >}}
```{r}
# Filter out pre- and during-Pandemic data.
df <- df |>
filter(df$date >= as.Date("2021-10-01"))
```
## Patterns in Taxi Data
```{r}
#| message: false
#| warning: false
# Pivot by trip distance bin.
pivot_trip_distance_df <- df |>
mutate(
temperature = round(temperature)
) |>
mutate(
up_to_ten_mile_trips = trip_count - rowSums(across(ends_with("mile_trips")))
) |>
pivot_longer(
cols=c(ends_with("mile_trips")),
names_to="trip_type",
values_to="trip_type_count",
) |>
mutate(trip_type = factor(trip_type,
levels = c(
"half_mile_trips",
"one_mile_trips",
"two_mile_trips",
"three_mile_trips",
"five_mile_trips",
"up_to_ten_mile_trips"
),
labels = c(
"Up to Half-Mile Trips",
"Up to One-Mile Trips",
"Up to Two-Mile Trips",
"Up to Three-Mile Trips",
"Up to Five-Mile Trips",
"Up to Ten-Mile Trips"
),
ordered = TRUE))
```
{{< include sections/3/2_taxi_usage_patterns.qmd >}}
## Patterns in Weather Data
{{< include sections/3/3_patterns_in_weather_data.qmd >}}
## Weather vs. Trips: Can We Define “Nice” Weather from Ridership Patterns?
{{< include sections/3/4_weather_vs_trips_count.qmd >}}
{{< include sections/3/4_weather_vs_trips.qmd >}}
## Doing the Timeshift
{{< include sections/3/5_timeshifts.qmd >}}