-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathtidytuesday_201914_seattle_bike_counters.r
67 lines (60 loc) · 1.94 KB
/
tidytuesday_201914_seattle_bike_counters.r
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
library(tidyverse)
library(lubridate)
library(viridis)
options(lubridate.week.start = 1)
raw_data <- read_csv(
paste0(
'https://raw.githubusercontent.com/rfordatascience/tidytuesday/',
'master/data/2019/2019-04-02/bike_traffic.csv'
),
col_types = list(
date = col_datetime('%m/%d/%Y %H:%M:%S %p'),
bike_count = col_integer(),
ped_count = col_integer()
)
)
bike_traffic <- raw_data %>%
filter(!is.na(bike_count), bike_count < 2000, date >= ymd(20140101))
bike_traffic_totals <- bike_traffic %>%
mutate(wday = wday(date, label = TRUE), hour = hour(date)) %>%
group_by(crossing, direction, wday, hour) %>%
summarize(total = sum(bike_count)) %>%
group_by(crossing, direction) %>%
mutate(
percentage = total / max(total) * 100,
name = paste0(crossing, ' (', direction, ')')
)
levels <- c(
'39th Ave NE Greenway at NE 62nd St (North)',
'39th Ave NE Greenway at NE 62nd St (South)',
'Broadway Cycle Track North Of E Union St (North)',
'Broadway Cycle Track North Of E Union St (South)',
'Burke Gilman Trail (North)',
'Burke Gilman Trail (South)',
'Elliot Bay Trail (North)',
'Elliot Bay Trail (South)',
'NW 58th St Greenway at 22nd Ave (West)',
'NW 58th St Greenway at 22nd Ave (East)',
'Sealth Trail (North)',
'Sealth Trail (South)',
'MTS Trail (East)'
)
bike_traffic_totals %>%
mutate(name = factor(name, levels = levels)) %>%
ggplot() +
geom_tile(aes(x = hour, y = wday, fill = percentage)) +
scale_x_continuous(breaks = 0:23) +
scale_fill_viridis(breaks = c(0, 100), labels = c('low', 'high')) +
facet_wrap(~ name, ncol = 2, scales = 'free') +
labs(
x = 'Time of Day',
y = 'Weekday',
fill = '',
title = "Seattle's Bike Counts per Time of Day and Weekday 2014-2019",
subtitle = '#tidytuesday 14|2019',
caption = '© 2019 spren9er'
)
ggsave(
'images/tidytuesday_201914_seattle_bike_counters.png',
width = 10, height = 13, bg = 'transparent'
)