@@ -47,14 +47,12 @@ rd <- rename(rd, participant_id = ID_PESS ,
4747# Recode modes as strings
4848mode_df <- data.frame (
4949 mode_int = append(c(1 : 17 ), NA ),
50- mode_string = c(rep(' bus' , 5 ), ' car_driver ' ,
51- ' car_passenger ' , ' taxi ' ,
52- rep( ' van ' , 3 ), ' subway' ,
50+ mode_string = c(rep(' bus' , 5 ), rep( ' car ' , 2 ) ,
51+ ' taxi ' , rep( ' van ' , 3 ),
52+ ' subway' ,
5353 ' train' , ' motorbike' ,
5454 ' bicycle' , ' walk' , ' others' , NA )
5555
56-
57-
5856)
5957
6058# Convert numeric to string modes
@@ -76,10 +74,27 @@ ggplot(rd %>%
7674 geom_text(aes(label = perc ), position = position_dodge(width = 0.9 ), vjust = - 0.25 , color = " blue" ) +
7775 theme_minimal() +
7876 theme(axis.text.x = element_text(angle = 90 , hjust = 1 )) +
79- labs(x = " " , y = " percentage(%)" , title = " Main Mode distribution" )
77+ labs(x = " " , y = " percentage(%)" , title = " Main Mode distribution - without weights" )
78+ # )
79+
80+ sum_total_trip_weight <- sum(rd $ FE_VIA , na.rm = T )
81+
82+ # plotly::ggplotly(
83+ ggplot(rd %> %
84+ filter(! is.na(trip_mode )) %> %
85+ group_by(trip_mode ) %> %
86+ summarise(sum_trip_weights = sum(FE_VIA )) %> %
87+ mutate(perc = round(sum_trip_weights / sum(sum_trip_weights ) * 100 , 1 )),
88+ aes(x = trip_mode , y = perc )) +
89+ geom_bar(position = ' dodge' , stat = ' identity' ) +
90+ geom_text(aes(label = perc ), position = position_dodge(width = 0.9 ), vjust = - 0.25 , color = " blue" ) +
91+ theme_minimal() +
92+ theme(axis.text.x = element_text(angle = 90 , hjust = 1 )) +
93+ labs(x = " " , y = " percentage(%)" , title = " Main Mode distribution - with weights" )
8094# )
8195
8296
97+
8398# Define distance categories
8499dist_cat <- c(" 0-6 km" , " 7-9 km" , " 10+ km" )
85100
@@ -99,4 +114,33 @@ ggplot(rd %>%
99114 geom_text(aes(label = perc ), position = position_dodge(width = 0.9 ), vjust = - 0.25 , color = " blue" ) +
100115 theme_minimal() +
101116 theme(axis.text.x = element_text(angle = 90 , hjust = 1 )) +
102- labs(x = " " , y = " percentage(%)" , title = " Main Mode Distance distribution" )
117+ labs(x = " " , y = " percentage(%)" , title = " Main Mode Distance distribution" )
118+
119+ # Calculate mode speed from the dataset, but using mean distance and duration
120+ # Remove all trips with multiple modes
121+ # Using only commute mode as a proxy
122+ mode_speed <- rd %> % filter(is.na(MODO2 ) & is.na(MODO3 ) & is.na(MODO4 ) &
123+ ((MOTIVO_O %in% c(1 , 2 , 3 ) & MOTIVO_D %in% 8 ) |
124+ (MOTIVO_D %in% c(1 , 2 , 3 ) & MOTIVO_O %in% 8 ))
125+ ) %> % group_by(trip_mode ) %> %
126+ summarise(mean (trip_distance ),
127+ speed = (mean(trip_distance )) / (mean(trip_duration ) / 60 ))
128+
129+
130+ # source_modes <- c('Bus', 'Walking')
131+ # target_modes <- c('Private Car')
132+ #
133+ # source_percentages <- c(0.16, 0.49)
134+ #
135+ # tt <- nrow(filter(rdr, ! trip_mode %in% c('99', 'Short Walking')))
136+ #
137+ # rdr <- create_scenario(rdr, scen_name = 'Scenario 1', source_modes = source_modes,
138+ # target_modes = target_modes, source_distance_cats = dist_cat,
139+ # source_trips = c(round(source_percentages[1] * tt),
140+ # round(source_percentages[2] * tt)))
141+ #
142+ # rdfinal <- rbind(rd, rdr)
143+
144+ # rdr %>% filter(rdfinal, scenario == 'Scenario 1' & ! trip_mode %in% c('Short Walking', "99", "Train", "Other", "Unspecified")) %>%
145+ # group_by(trip_mode) %>% summarise(count = n(), pert = n() / nrow(.) * 100)
146+
0 commit comments