-
Notifications
You must be signed in to change notification settings - Fork 1
/
Graphs2015.Rmd
463 lines (385 loc) · 13 KB
/
Graphs2015.Rmd
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
---
title: "Graphs - 2015"
author: ""
date: ""
output:
html_document:
fig_height: 6
fig_width: 10
---
<!-- Don't edit in between this line and the one below -->
```{r include=FALSE}
# Don't delete this chunk if you are using the DataComputing package
library(DataComputing)
```
*Source file*
```{r, results='asis', echo=FALSE}
includeSourceDocuments()
```
<!-- Don't edit the material above this line -->
**Downloading and Formatting the Data**
```{r}
col_names <- c("p_time", "d_time", "num_passengers", "distance", "p_lat", "p_long", "d_lat", "d_long", "payment_type", "fare", "total")
#yellow taxi data 12/2015
y15_12 <- read.csv('/Users/siyaoma/Desktop/2015/yellow_tripdata_2015-12_clean.csv')
names(y15_12) <- col_names
y15_12<- y15_12 %>%
mutate(month = lubridate::month(p_time))
#yellow taxi data 11/2015
y15_11 <- read.csv('/Users/siyaoma/Desktop/2015/yellow_tripdata_2015-11_clean.csv')
names(y15_11) <- col_names
y15_11<- y15_11 %>%
mutate(month = lubridate::month(p_time))
#yellow taxi data 10/2015
y15_10 <- read.csv('/Users/siyaoma/Desktop/2015/yellow_tripdata_2015-10_clean.csv')
names(y15_10) <- col_names
y15_10<- y15_10 %>%
mutate(month = lubridate::month(p_time))
#yellow taxi data 09/2015
y15_09 <- read.csv('/Users/siyaoma/Desktop/2015/yellow_tripdata_2015-09_clean.csv')
names(y15_09) <- col_names
y15_09<- y15_09 %>%
mutate(month = lubridate::month(p_time))
#yellow taxi data 08/2015
y15_08 <- read.csv('/Users/siyaoma/Desktop/2015/yellow_tripdata_2015-08_clean.csv')
names(y15_08) <- col_names
y15_08<- y15_08 %>%
mutate(month = lubridate::month(p_time))
#yellow taxi data 07/2015
y15_07 <- read.csv('/Users/siyaoma/Desktop/2015/yellow_tripdata_2015-07_clean.csv')
names(y15_07) <- col_names
y15_07<- y15_07 %>%
mutate(month = lubridate::month(p_time))
#yellow taxi data 06/2015
y15_06 <- read.csv('/Users/siyaoma/Desktop/2015/yellow_tripdata_2015-06_clean.csv')
names(y15_06) <- col_names
y15_06<- y15_06 %>%
mutate(month = lubridate::month(p_time))
#yellow taxi data 05/2015
y15_05 <- read.csv('/Users/siyaoma/Desktop/2015/yellow_tripdata_2015-05_clean.csv')
names(y15_05) <- col_names
y15_05 <- y15_05 %>%
mutate(month = lubridate::month(p_time))
#yellow taxi data 04/2015
y15_04 <- read.csv('/Users/siyaoma/Desktop/2015/yellow_tripdata_2015-04_clean.csv')
names(y15_04) <- col_names
y15_04 <- y15_04 %>%
mutate(month = lubridate::month(p_time))
#yellow taxi data 03/2015
y15_03 <- read.csv('/Users/siyaoma/Desktop/2015/yellow_tripdata_2015-03_clean.csv')
names(y15_03) <- col_names
y15_03 <- y15_03 %>%
mutate(month = lubridate::month(p_time))
#yellow taxi data 02/2015
y15_02 <- read.csv('/Users/siyaoma/Desktop/2015/yellow_tripdata_2015-02_clean.csv')
names(y15_02) <- col_names
y15_02 <- y15_02 %>%
mutate(month = lubridate::month(p_time))
#yellow taxi data 01/2015
y15_01 <- read.csv('/Users/siyaoma/Desktop/2015/yellow_tripdata_2015-01_clean.csv')
names(y15_01) <- col_names
y15_01 <- y15_01 %>%
mutate(month = lubridate::month(p_time))
y15 <- rbind(y15_12, y15_11, y15_10, y15_09, y15_08, y15_07, y15_06, y15_05, y15_04, y15_03, y15_02, y15_01)
y15 <- y15 %>%
mutate(taxi_color = "yellow") %>%
mutate(yday = lubridate::yday(p_time)) %>%
mutate(mday = lubridate::mday(p_time)) %>%
mutate(weekday = lubridate::wday(p_time)) %>%
mutate(hour = str_sub(p_time, -9, -7))
```
```{r}
col_names <- c("p_time", "d_time", "p_lat", "p_long", "d_lat", "d_long", "num_passengers", "distance", "fare", "total", "payment_type")
#green taxi data 12/2015
g15_12 <- read.csv('/Users/siyaoma/Desktop/2015/green_tripdata_2015-12_clean.csv')
names(g15_12) <- col_names
g15_12<- g15_12 %>%
mutate(month = lubridate::month(p_time))
#green taxi data 11/2015
g15_11 <- read.csv('/Users/siyaoma/Desktop/2015/green_tripdata_2015-11_clean.csv')
names(g15_11) <- col_names
g15_11<- g15_11 %>%
mutate(month = lubridate::month(p_time))
#green taxi data 10/2015
g15_10 <- read.csv('/Users/siyaoma/Desktop/2015/green_tripdata_2015-10_clean.csv')
names(g15_10) <- col_names
g15_10<- g15_10 %>%
mutate(month = lubridate::month(p_time))
#green taxi data 09/2015
g15_09 <- read.csv('/Users/siyaoma/Desktop/2015/green_tripdata_2015-09_clean.csv')
names(g15_09) <- col_names
g15_09<- g15_09 %>%
mutate(month = lubridate::month(p_time))
#green taxi data 08/2015
g15_08 <- read.csv('/Users/siyaoma/Desktop/2015/green_tripdata_2015-08_clean.csv')
names(g15_08) <- col_names
g15_08<- g15_08 %>%
mutate(month = lubridate::month(p_time))
#green taxi data 07/2015
g15_07 <- read.csv('/Users/siyaoma/Desktop/2015/green_tripdata_2015-07_clean.csv')
names(g15_07) <- col_names
g15_07<- g15_07 %>%
mutate(month = lubridate::month(p_time))
#green taxi data 06/2015
g15_06 <- read.csv('/Users/siyaoma/Desktop/2015/green_tripdata_2015-06_clean.csv')
names(g15_06) <- col_names
g15_06<- g15_06 %>%
mutate(month = lubridate::month(p_time))
#green taxi data 05/2015
g15_05 <- read.csv('/Users/siyaoma/Desktop/2015/green_tripdata_2015-05_clean.csv')
names(g15_05) <- col_names
g15_05 <- g15_05 %>%
mutate(month = lubridate::month(p_time))
#green taxi data 04/2015
g15_04 <- read.csv('/Users/siyaoma/Desktop/2015/green_tripdata_2015-04_clean.csv')
names(g15_04) <- col_names
g15_04 <- g15_04 %>%
mutate(month = lubridate::month(p_time))
#green taxi data 03/2015
g15_03 <- read.csv('/Users/siyaoma/Desktop/2015/green_tripdata_2015-03_clean.csv')
names(g15_03) <- col_names
g15_03 <- g15_03 %>%
mutate(month = lubridate::month(p_time))
#green taxi data 02/2015
g15_02 <- read.csv('/Users/siyaoma/Desktop/2015/green_tripdata_2015-02_clean.csv')
names(g15_02) <- col_names
g15_02 <- g15_02 %>%
mutate(month = lubridate::month(p_time))
#green taxi data 01/2015
g15_01 <- read.csv('/Users/siyaoma/Desktop/2015/green_tripdata_2015-01_clean.csv')
names(g15_01) <- col_names
g15_01 <- g15_01 %>%
mutate(month = lubridate::month(p_time))
g15 <- rbind(g15_12, g15_11, g15_10, g15_09, g15_08, g15_07, g15_06, g15_05, g15_04, g15_03, g15_02, g15_01)
g15 <- g15 %>%
mutate(taxi_color = "green") %>%
mutate(yday = lubridate::yday(p_time)) %>%
mutate(mday = lubridate::mday(p_time)) %>%
mutate(weekday = lubridate::wday(p_time)) %>%
mutate(hour = str_sub(p_time, -9, -7))
```
```{r}
tot15 <- rbind(y15, g15)
```
**Fares**
```{r}
#total amount paid (including surchage, tolls, etc) v. distance traveled
#outliers filtered out
tot15 %>% #entire year
ggplot(aes(y = total, x = distance)) +
geom_point() +
geom_smooth(se = FALSE) +
ggtitle("Amount v. Distance - Entire Year w/ outliers")
tot15 %>% #entire year
ggplot(aes(y = total, x = distance, color = taxi_color)) +
geom_point() +
geom_smooth(se = FALSE) +
ggtitle("Amount v. Distance - Entire Year w/ outliers (Green v. Yellow Taxi)")
tot15 %>% #faceted by month
ggplot(aes(y = total, x = distance)) +
geom_point() +
geom_smooth(se = FALSE) +
facet_wrap(~ month) +
ggtitle("Amount v. Distance - Monthly w/ outliers")
```
**OUTLIERS FILTERED OUT FOR ALL SUBSEQUENT GRAPHS**
```{r}
tot15 <- tot15 %>%
filter(distance < 50, total > 0, total < 100)
tot15 %>% #entire year, without outliers
ggplot(aes(y = total, x = distance)) +
geom_point() +
geom_smooth(se = FALSE) +
ggtitle("Amount v. Distance - Entire Year")
tot15 %>% #faceted by month, without outliers
ggplot(aes(y = total, x = distance)) +
geom_point() +
geom_smooth(se = FALSE) +
facet_wrap(~ month) +
ggtitle("Amount v. Distance - Monthly")
```
```{r}
#average fare by month, without outliers
tot15_month_ave_fare <- tot15 %>%
group_by(month)%>%
summarize(ave=mean(total))
tot15_month_ave_fare %>%
ggplot(aes(x=month, y=ave)) +
geom_point() +
geom_line() +
scale_x_continuous(breaks=seq(1,12,1)) +
ggtitle("Average Fare v. Month")
#average fare by day of the week, without outliers
tot15_day_ave_fare <- tot15 %>%
group_by(weekday)%>%
summarize(ave=mean(total))
tot15_day_ave_fare %>%
ggplot(aes(x=weekday, y=ave)) +
geom_point() +
geom_line() +
scale_x_continuous(breaks=seq(1,7,1)) +
ggtitle("Average Fare v. Day")
tot15_day_ave_fare %>%
ggplot(aes(x=weekday, y=ave)) +
geom_bar(stat ="identity") +
scale_x_continuous(breaks=seq(1,7,1)) +
ggtitle("Average Fare v. Day")
#average fare by time of day, without outliers
tot15_hour_ave_fare <- tot15 %>%
group_by(hour) %>%
summarize(ave=mean(total))
tot15_hour_ave_fare %>%
ggplot(aes(x=hour, y=ave)) +
geom_point() +
geom_line() +
ggtitle("Average Fare v. Hour")
tot15_hour_ave_fare %>%
ggplot(aes(x=hour, y=ave)) +
geom_bar(stat ="identity") +
ggtitle("Average Fare v. Hour")
```
**Trip Length**
```{r}
#average trip length by month, without outliers
tot15_month_ave_dist <- tot15 %>%
filter(distance > 0, distance < 50) %>%
group_by(month)%>%
summarize(ave=mean(distance))
tot15_month_ave_dist %>%
ggplot(aes(x=month, y=ave)) +
geom_point() +
geom_line() +
scale_x_continuous(breaks=seq(1,12,1)) +
ggtitle("Average Trip Length v. Month")
tot15_month_ave_dist %>%
ggplot(aes(x=month, y=ave)) +
geom_bar(stat ="identity") +
scale_x_continuous(breaks=seq(1,12,1)) +
ggtitle("Average Trip Length v. Month")
#average trip length by day of the week, without outliers
tot15_day_ave_dist <- tot15 %>%
filter(distance > 0, distance < 50) %>%
group_by(weekday)%>%
summarize(ave=mean(distance))
tot15_day_ave_dist %>%
ggplot(aes(x=weekday, y=ave)) +
geom_point() +
geom_line() +
scale_x_continuous(breaks=seq(1,7,1)) +
ggtitle("Average Trip Length v. Day")
tot15_day_ave_dist %>%
ggplot(aes(x=weekday, y=ave)) +
geom_bar(stat ="identity") +
scale_x_continuous(breaks=seq(1,7,1)) +
ggtitle("Average Trip Length v. Day")
#average trip length by time of day
tot15_hour_ave_dist <- tot15 %>%
filter(distance > 0, distance < 50) %>%
group_by(hour) %>%
summarize(ave=mean(distance))
tot15_hour_ave_dist %>%
ggplot(aes(x=hour, y=ave)) +
geom_point() +
geom_line() +
ggtitle("Average Trip Length v. Hour")
tot15_hour_ave_dist %>%
ggplot(aes(x=hour, y=ave)) +
geom_bar(stat ="identity") +
ggtitle("Average Trip Length v. Hour")
```
**Number of Trips**
```{r}
#total number of taxi rides for each day of the year 2015
tot15_year <- tot15 %>%
group_by(yday) %>%
summarise(tot = n())
tot15_year %>%
ggplot(aes(y = tot, x = yday, col = yday)) +
geom_bar(stat ="identity") +
ggtitle("Number of Trips v. Day of Year")
tot15_year %>%
ggplot(aes(y = tot, x = yday, col = yday)) +
geom_line() +
ggtitle("Number of Trips v. Day of Year")
#total number of taxi rides per month
tot15_month <- tot15 %>%
group_by(mday) %>%
summarise(tot = n())
tot15_month %>%
ggplot(aes(y = tot, x = mday, col = mday)) +
geom_bar(stat ="identity") +
scale_x_continuous(breaks=seq(1,12,1)) +
ggtitle("Number of Trips v. Month")
#total number of taxi rides for each day of week
tot15_day <- tot15 %>%
group_by(weekday) %>%
summarise(tot = n())
tot15_day %>%
ggplot(aes(y = tot, x = weekday, col = weekday)) +
geom_bar(stat ="identity") +
scale_x_continuous(breaks=seq(1,7,1)) +
ggtitle("Number of Trips v. Day of Week")
#total number of taxi rides for each day of the week (normalized)
total <- sum(tot15_day$tot)
tot15_day_ave <- tot15_day %>%
mutate(ave = tot15_day$tot/total)
tot15_day_ave %>%
ggplot(aes(y = ave, x = weekday)) +
geom_bar(stat ="identity") +
scale_x_continuous(breaks=seq(1,7,1)) +
ggtitle("Number of Trips v. Day of Week - Normalized")
#total number of taxi rides per hour
tot15_hour <- tot15 %>%
group_by(hour, weekday) %>%
summarise(tot = n())
tot15_hour %>%
ggplot(aes(y = tot, x = hour, fill = weekday)) +
geom_bar(stat ="identity") +
ggtitle("Number of Trips v. Hour")
#total number of taxi rides per hour (normalized)
tot15_hour_ave <- tot15 %>%
group_by(hour) %>%
summarise(tot = n()) %>%
mutate(ave = tot/sum(tot))
tot15_hour_ave %>%
ggplot(aes(y = ave, x = hour)) +
geom_bar(stat ="identity") +
ggtitle("Number of Trips v. Hour - Normalized")
```
**Number of Passengers**
```{r}
#number of passengers per day of year
tot15_passengers_year <- tot15 %>%
group_by(yday) %>%
summarize(tot = sum(num_passengers))
tot15_passengers_year %>%
ggplot(aes(x = yday, y = tot)) +
geom_bar(stat ="identity") +
ggtitle("Number of Passengers v. Day of Year")
#number of passengers per month
tot15_passengers_month <- tot15 %>%
group_by(month) %>%
summarize(tot = sum(num_passengers))
tot15_passengers_month %>%
ggplot(aes(x = month, y = tot)) +
geom_bar(stat ="identity") +
scale_x_continuous(breaks=seq(1,12,1)) +
ggtitle("Number of Passengers v. Month")
#number of passengers per weekday
tot15_passengers_day <- tot15 %>%
group_by(weekday) %>%
summarize(tot = sum(num_passengers))
tot15_passengers_day %>%
ggplot(aes(x = weekday, y = tot)) +
geom_bar(stat ="identity") +
scale_x_continuous(breaks=seq(1,7,1)) +
ggtitle("Number of Passengers v. Day of Week")
#number of passengers per hour
tot15_passengers_hour <- tot15 %>%
group_by(hour) %>%
summarize(tot = sum(num_passengers))
tot15_passengers_hour %>%
ggplot(aes(x = hour, y = tot)) +
geom_bar(stat ="identity") +
ggtitle("Number of Passengers v. Hour")
```