From 6f535180bfe3138eb3a30ec690cfd488bb43e158 Mon Sep 17 00:00:00 2001 From: schlenther Date: Fri, 30 Aug 2024 11:24:27 +0200 Subject: [PATCH] minor improvements in R code --- src/main/R/drtAnalysis/plotRunSummaries.R | 67 ++++++++++++++++ .../drtAnalysis/readValuesFromRunSummaries.R | 76 +------------------ .../VIA-data/KEXI-shiny-dashboard.R | 8 +- src/main/R/modeAnalysis-kexiArea.R | 10 ++- 4 files changed, 78 insertions(+), 83 deletions(-) create mode 100644 src/main/R/drtAnalysis/plotRunSummaries.R diff --git a/src/main/R/drtAnalysis/plotRunSummaries.R b/src/main/R/drtAnalysis/plotRunSummaries.R new file mode 100644 index 0000000..ef53500 --- /dev/null +++ b/src/main/R/drtAnalysis/plotRunSummaries.R @@ -0,0 +1,67 @@ +library(ggplot2) +library(dplyr) +library(tidyr) + +mainDir <- "E:/matsim-kelheim/v3.1.1/output-KEXI-2.45-AV--0.0/" + +transposed_result <- read.csv(paste(mainDir, "results-deutsch.csv", sep=""), check.names = FALSE) +#names(transposed_result) <- make.names(names(transposed_result), unique = TRUE, allow_ = FALSE) + +# Betriebszeiten umschreiben +transposed_result$Betriebszeiten <- ifelse(transposed_result$Betriebszeiten == TRUE, "0h - 24h", "9h - 16h") + + +results <- transposed_result %>% + gather(key = "parameter", value = "mean", -Geschwindigkeit, -Bediengebiet, -Flottengroeße, -Intermodal, -Betriebszeiten) + + +plotByConfiguration <- function(parameterStr){ + + # Filtern der Daten für die gewünschten Parameter + plot_data <- results %>% + filter(parameter == parameterStr, + Intermodal == TRUE | Bediengebiet == "AV 2024") + + # Funktion zum Anpassen der Facet-Labels + label_function <- function(value) { + paste(value, "m/s") + } + + # Erstellen des Facet-Plots + ggplot(plot_data, aes(x = Flottengroeße, y = mean, color = Bediengebiet, linetype = as.factor(Betriebszeiten), group = interaction(Bediengebiet, Betriebszeiten))) + + geom_line(size = 1.2) + + geom_point(size = 3, + #aes(shape = as.factor(intermodal)) + ) + + facet_wrap(~ Geschwindigkeit, + labeller = labeller(Geschwindigkeit = label_function) + ,scales = "free" + ) + + labs(title = paste(parameterStr, "nach Geschwindigkeit, Flottengröße, Bediengebiet und Betriebszeiten"), + x = "Flottengröße", + y = parameterStr, + color = "Bediengebiet", + linetype = "Betriebszeiten" + #,shape = "Intermodal" + ) + + #theme_dark() + + theme( + plot.title = element_text(size = 20, face = "bold"), # Titelgröße anpassen + axis.title.x = element_text(size = 18), # X-Achsentitelgröße anpassen + axis.title.y = element_text(size = 18), # Y-Achsentitelgröße anpassen + axis.text = element_text(size = 14), # Achsentextgröße anpassen + legend.title = element_text(size = 18), # Legendentitelgröße anpassen + legend.text = element_text(size = 14), # Legendtextgröße anpassen + strip.text = element_text(size = 18, face = "bold") # Facet-Textgröße anpassen + ) + +} + +unique(results$parameter) +plotByConfiguration("Bediente Anfragen") +plotByConfiguration("Mittl. Wartezeit") +plotByConfiguration("Avg. ride distance [km]") +plotByConfiguration("Empty ratio") +plotByConfiguration("Total vehicle mileage [km]") +plotByConfiguration("Avg. fare [MoneyUnit]" ) +plotByConfiguration("Pax per veh-km") \ No newline at end of file diff --git a/src/main/R/drtAnalysis/readValuesFromRunSummaries.R b/src/main/R/drtAnalysis/readValuesFromRunSummaries.R index 515654d..778a570 100644 --- a/src/main/R/drtAnalysis/readValuesFromRunSummaries.R +++ b/src/main/R/drtAnalysis/readValuesFromRunSummaries.R @@ -112,84 +112,10 @@ print(transposed_result) write_csv(transposed_result, paste(mainDir, "results.csv", sep="")) + ##################################################################### ######PLOTS#### -# Filtern der Daten für die gewünschten Parameter -#plot_data <- results %>% -# filter(parameter %in% c("Handled Requests")) - -## Erstellen des interaktiven dreidimensionalen Plots -#plot <- plot_ly(plot_data, -# x = ~speed, -# y = ~fleetSize, -# z = ~mean, -# color = ~area, -# type = "scatter3d", -# mode = "markers", -# marker = list(size = 5)) %>% -# add_markers() %>% -# layout(title = "Handled Requests by speed, area and Fleet Size", -# scene = list(xaxis = list(title = "Speed"), -# yaxis = list(title = "Fleet Size"), -# zaxis = list(title = "Handled Requests"))) -# -## Plot anzeigen -#plot - -# Erstellen des interaktiven dreidimensionalen Plots mit Mesh -plot <- plot_ly(plot_data) %>% - add_mesh(x = ~speed, - y = ~fleetSize, - z = ~mean, - color = ~area, - opacity = 0.6, # Opazität der Flächen - text = ~paste("Area:", area), - colors = c("#1f77b4", "#ff7f0e", "#2ca02c", "#d62728", "#9467bd", "#8c564b", "#e377c2", "#7f7f7f", "#bcbd22", "#17becf"), # Farben für jede Area - showscale = TRUE) %>% - layout(title = "Handled Requests by speed, fleetSize and area", - scene = list(xaxis = list(title = "Speed"), - yaxis = list(title = "Fleet Size"), - zaxis = list(title = "Mean Handled Requests"))) - -# Plot anzeigen -plot - -#mesh_data <- plot_data %>% -# group_by(area) %>% -# summarise(speed = mean(speed), -# fleetSize = mean(fleetSize), -# mean = mean(mean)) %>% -# arrange(area) - -## Erstellen des interaktiven dreidimensionalen Plots mit Meshes für jede Area -#plot <- plot_ly(plot_data) %>% -# add_trace(x = ~speed, -# y = ~fleetSize, -# z = ~mean, -# color = ~area, -# type = "scatter3d", -# mode = "markers", -# marker = list(size = 5)) %>% -# add_trace(data = mesh_data, -# x = ~speed, -# y = ~fleetSize, -# z = ~mean, -# color = ~area, -# type = "mesh3d", -# opacity = 0.6, # Opazität der Flächen -# colorscale = "Viridis", # Farbskala für die Flächen -# showscale = TRUE) %>% -# layout(title = "Handled Requests by speed, fleetSize and area", -# scene = list(xaxis = list(title = "Speed"), -# yaxis = list(title = "Fleet Size"), -# zaxis = list(title = "Mean Handled Requests"))) - -## Plot anzeigen -#plot - - -########################### plotByConfiguration <- function(parameterStr){ # Filtern der Daten für die gewünschten Parameter diff --git a/src/main/R/drtDemandAnalysis/VIA-data/KEXI-shiny-dashboard.R b/src/main/R/drtDemandAnalysis/VIA-data/KEXI-shiny-dashboard.R index 68c9036..0ef7e48 100644 --- a/src/main/R/drtDemandAnalysis/VIA-data/KEXI-shiny-dashboard.R +++ b/src/main/R/drtDemandAnalysis/VIA-data/KEXI-shiny-dashboard.R @@ -16,16 +16,16 @@ library(zoo) #for moving averages #### read data. #input files -requests_file <- "D:/svn/shared-svn/projects/KelRide/data/KEXI/VIA_data_2024_05_22/Fahrtanfragen-2024-05-22.csv" -shifts_file <- "D:/svn/shared-svn/projects/KelRide/data/KEXI/VIA_data_2024_05_22/Fahrerschichten-2024-05-22.csv" +requests_file <- "D:/shared-svn/projects/KelRide/data/KEXI/VIA_data/raw-data/Fahrtanfragen.csv" +shifts_file <- "D:/shared-svn/projects/KelRide/data/KEXI/VIA_data/raw-data/Fahrerschichten.csv" #parse data -data <- read.csv2(requests_file, sep = ",", stringsAsFactors = FALSE, header = TRUE, encoding = "UTF-8") +data <- read.csv2(requests_file, sep = ";", stringsAsFactors = FALSE, header = TRUE, encoding = "UTF-8") #data_fahrerschichten <- read.csv2(shifts_file, sep = ",", stringsAsFactors = FALSE, header = TRUE, encoding = "UTF-8") %>% # mutate(time = ymd_hms(Datum), # date = date(time)) -data_fahrerschichten <- read.csv2(shifts_file, sep = ",", stringsAsFactors = FALSE, header = TRUE, encoding = "UTF-8") %>% +data_fahrerschichten <- read.csv2(shifts_file, sep = ";", stringsAsFactors = FALSE, header = TRUE, encoding = "UTF-8") %>% mutate(Start = ymd_hms(Schichtstart), Ende = ymd_hms(Schichtende), Dauer_h = as.numeric(Ende - Start, units="hours"), diff --git a/src/main/R/modeAnalysis-kexiArea.R b/src/main/R/modeAnalysis-kexiArea.R index 9dd68ae..cde5523 100644 --- a/src/main/R/modeAnalysis-kexiArea.R +++ b/src/main/R/modeAnalysis-kexiArea.R @@ -1,7 +1,7 @@ library(sf) library(matsim) - - +library(tidyverse) +library(plotly) drtArea <- st_read("D:/public-svn/matsim/scenarios/countries/de/kelheim/shp/prepare-network/av-and-drt-area.shp") @@ -20,7 +20,9 @@ largeAV_filtered <- largeAVTrips %>% #base -plot_mainmode_piechart(base_filtered) +p <- plot_mainmode_piechart(base_filtered) +p2 <- p %>% layout(title = "Base Case") +p2 #base vs KEXI plot_compare_mainmode_barchart(base_filtered, kexi_filtered) @@ -33,4 +35,4 @@ plot_compare_mainmode_barchart(base_filtered, largeAV_filtered) plot_compare_mainmode_sankey(base_filtered, largeAV_filtered, show_onlychanges = TRUE) plot_mainmode_piechart(largeAV_filtered) - +matsim::plot_map_trips(kexi_filtered, crs = 25832)