Skip to content

Commit cec33b9

Browse files
committed
Draw distance distribution
1 parent d0f1efa commit cec33b9

1 file changed

Lines changed: 36 additions & 9 deletions

File tree

code/scenarios/sao paulo/streamline_travel_survey.R

Lines changed: 36 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# Load libraries
21
library(tidyverse)
32
library(plotly)
43

@@ -39,8 +38,8 @@ rd <- rename(rd, participant_id = ID_PESS ,
3938
walking_time_origin = ANDA_O,
4039
walking_time_dest = ANDA_D,
4140
trip_duration = DURACAO,
42-
mode = MODOPRIN,
43-
distance = DISTANCIA,
41+
trip_mode = MODOPRIN,
42+
trip_distance = DISTANCIA,
4443
row_id = ID_ORDEM
4544

4645
)
@@ -52,24 +51,52 @@ mode_df <- data.frame(
5251
'car_passenger', 'taxi',
5352
rep('van', 3), 'subway',
5453
'train', 'motorbike',
55-
'bicycle', 'walk', 'others', 'NAs')
54+
'bicycle', 'walk', 'others', NA)
5655

5756

5857

5958
)
6059

61-
rd$mode_string <- as.character(mode_df$mode_string[match(rd$mode, mode_df$mode_int)])
60+
# Convert numeric to string modes
61+
rd$mode_string <- as.character(mode_df$mode_string[match(rd$trip_mode, mode_df$mode_int)])
62+
rd$trip_mode <- rd$mode_string
63+
rd$mode_string <- NULL
64+
65+
# Covert distance in meters to kms
66+
rd$trip_distance <- rd$trip_distance / 1000
6267

6368
# plotly::ggplotly(
6469
ggplot(rd %>%
65-
filter(!is.na(mode)) %>%
66-
group_by(mode_string) %>%
70+
filter(!is.na(trip_mode)) %>%
71+
group_by(trip_mode) %>%
6772
summarise(count = n()) %>%
6873
mutate(perc = round(count/sum(count) * 100, 1)),
69-
aes(x = mode_string, y = perc)) +
74+
aes(x = trip_mode, y = perc)) +
7075
geom_bar(position = 'dodge', stat='identity') +
7176
geom_text(aes(label = perc), position = position_dodge(width=0.9), vjust=-0.25, color = "blue") +
7277
theme_minimal() +
7378
theme(axis.text.x = element_text(angle = 90, hjust = 1)) +
7479
labs(x = "", y = "percentage(%)", title = "Main Mode distribution")
75-
# )
80+
# )
81+
82+
83+
# Define distance categories
84+
dist_cat <- c("0-6 km", "7-9 km", "10+ km")
85+
86+
# Initialize them
87+
rd$trip_distance_cat <- NULL
88+
rd$trip_distance_cat[rd$trip_distance > 0 & rd$trip_distance < 7] <- dist_cat[1]
89+
rd$trip_distance_cat[rd$trip_distance >= 7 & rd$trip_distance < 10] <- dist_cat[2]
90+
rd$trip_distance_cat[rd$trip_distance >= 10] <- dist_cat[3]
91+
92+
ggplot(rd %>%
93+
filter(!is.na(trip_distance_cat)) %>%
94+
group_by(trip_distance_cat) %>%
95+
summarise(count = n()) %>%
96+
mutate(perc = round(count/sum(count) * 100, 1)),
97+
aes(x = trip_distance_cat, y = perc)) +
98+
geom_bar(position = 'dodge', stat='identity') +
99+
geom_text(aes(label = perc), position = position_dodge(width=0.9), vjust=-0.25, color = "blue") +
100+
theme_minimal() +
101+
theme(axis.text.x = element_text(angle = 90, hjust = 1)) +
102+
labs(x = "", y = "percentage(%)", title = "Main Mode Distance distribution")

0 commit comments

Comments
 (0)