Skip to content

Commit

Permalink
minor improvements in R code
Browse files Browse the repository at this point in the history
  • Loading branch information
tschlenther committed Aug 30, 2024
1 parent 2664de0 commit 6f53518
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 83 deletions.
67 changes: 67 additions & 0 deletions src/main/R/drtAnalysis/plotRunSummaries.R
Original file line number Diff line number Diff line change
@@ -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")
76 changes: 1 addition & 75 deletions src/main/R/drtAnalysis/readValuesFromRunSummaries.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions src/main/R/drtDemandAnalysis/VIA-data/KEXI-shiny-dashboard.R
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down
10 changes: 6 additions & 4 deletions src/main/R/modeAnalysis-kexiArea.R
Original file line number Diff line number Diff line change
@@ -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")

Expand All @@ -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)
Expand All @@ -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)

0 comments on commit 6f53518

Please sign in to comment.