Skip to content

Commit

Permalink
more forwards export multiple plots. ggPlot lasse ich erstmal weg.. u…
Browse files Browse the repository at this point in the history
…nd kombiniere dann in latex.
  • Loading branch information
kt86 committed Sep 27, 2024
1 parent 389e5d6 commit acbd9f5
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 41 deletions.
7 changes: 7 additions & 0 deletions src/main/R/KaiMT/plotFoodResults.R
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,13 @@ violin_plot_distances <- plot_ly(#data = df_tours,
showlegend = FALSE
)

print(violin_plot_distances %>% layout())
#scope <- kaleido()
#scope$transform(violin_plot_distances, "myplotKMT.pdf")
#rm(scope); gc()
#save_image(violin_plot_distances %>% layout(), "myplotKMT.pdf")
#open_file(filename)

# Display the plots separately
print(bar_plot %>% layout(title = 'Number of Vehicles by Vehicle Category'))
print(bar_plot_costs %>% layout(title = 'Total Costs by Vehicle Category'))
Expand Down
90 changes: 49 additions & 41 deletions src/main/R/KaiMT/plotFoodResults_multiDir.R
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,9 @@ for (subdir in subdirs) {
colorsKMT8 <- c("#1c18a0", "#9013fe" , "#1e54b6", "#760e95", "#3c71d9", "#aa108e", "#1f90cc","#DF0174")
colorsAna <- c("#1c18a0", "#1e54b6", "#1f90cc", "#3c71d9", "#9013fe", "#760e95", "#aa108e", "c40d1e", "#a40c2e", "#5e082c","#4e0c49","#3d1066")

xValue <- df_tours$vehicleCategory
yValue <- df_tours$travelDistance.kmö

### plotly ####
violin_plot_distances <- plot_ly(#data = df_tours,
x = ~df_tours$vehicleCategory,
Expand All @@ -173,40 +176,43 @@ for (subdir in subdirs) {

# # Display the plots separately
print(violin_plot_distances)
readline(prompt = "Drücken Sie [ENTER], um fortzufahren...")

# Optional: Plot als PNG speichern
# ggsave(filename = "violin_plot_distances.png", plot = violin_plot_distances_gg, width = 10, height = 5)

#filename <- paste(basename(subdir),".png")
#save_image(violin_plot_distances, filename)

# Füge den Plot und den Subdir-Namen dem Tibble hinzu
all_plots_DistViolin <- all_plots_DistViolin %>% add_row(subdir = basename(subdir), plot = list(violin_plot_distances))
###ENDE Plotly ####


####TEST mit ggplot
# Erstellen des Violin-Plots mit ggplot2
violin_plot_distances_gg <- ggplot(df_tours, aes(x = vehicleCategory, y = travelDistance.km., fill = vehicleCategory)) +
geom_violin(trim = FALSE, width = 1) +
geom_boxplot(width = 0.1, outlier.shape = NA) +
geom_jitter(position = position_jitter(width = 0.2), size = 1.5, alpha = 0.6) +
scale_y_continuous(limits = c(-45, max_y_km)) +
scale_fill_manual(values = colorsKMT8) + # Anpassung der Farben
labs(title = basename(subdir), x = "Vehicle Type", y = "Tour Distance (km)") +
theme_minimal() +
theme(legend.position = "none",
plot.title = element_text(hjust = 0.5, size = 16))

# Plot anzeigen
print(violin_plot_distances_gg)

# Optional: Plot als PNG speichern
# ggsave(filename = "violin_plot_distances.png", plot = violin_plot_distances_gg, width = 10, height = 5)


# Füge den Plot und den Subdir-Namen dem Tibble hinzu
all_plots_DistViolin_gg <- all_plots_DistViolin_gg %>% add_row(subdir = basename(subdir), plot = list(violin_plot_distances_gg))


#### Ende ggplot
# ####TEST mit ggplot
# # Erstellen des Violin-Plots mit ggplot2
# violin_plot_distances_gg <- ggplot(df_tours, aes(x = vehicleCategory, y = travelDistance.km., fill = vehicleCategory)) +
# geom_violin(trim = FALSE, width = 1) +
# geom_boxplot(width = 0.1, outlier.shape = NA) +
# geom_jitter(position = position_jitter(width = 0.2), size = 1.5, alpha = 0.6) +
# scale_y_continuous(limits = c(-45, max_y_km)) +
# scale_fill_manual(values = colorsKMT8) + # Anpassung der Farben
# labs(title = basename(subdir), x = "Vehicle Type", y = "Tour Distance (km)") +
# theme_minimal() +
# theme(legend.position = "none",
# plot.title = element_text(hjust = 0.5, size = 16))
#
# # Plot anzeigen
# print(violin_plot_distances_gg)
#
# # Optional: Plot als PNG speichern
# # ggsave(filename = "violin_plot_distances.png", plot = violin_plot_distances_gg, width = 10, height = 5)
#
#
# # Füge den Plot und den Subdir-Namen dem Tibble hinzu
# all_plots_DistViolin_gg <- all_plots_DistViolin_gg %>% add_row(subdir = basename(subdir), plot = list(violin_plot_distances_gg))
#
#
# #### Ende ggplot
}
else { message(paste("Datei nicht gefunden in:", subdir, file_path_veh))} }

Expand All @@ -218,28 +224,30 @@ for (subdir in subdirs) {
# Test: Durchlaufen der Tibble und Anzeigen der Plots
for (i in seq_len(nrow(all_plots_DistViolin))) {
print(all_plots_DistViolin$plot[[i]])

}


# Kombiniere die plotly-Plots zu einem einzigen Subplot
combined_plot <- subplot(all_plots_DistViolin$plot, nrows = length(all_plots_DistViolin$plot) %/% 2 + length(all_plots_DistViolin$plot) %% 2, shareX = TRUE, shareY = TRUE)

# Zeige den kombinierten Plot an
combined_plot


###ggplot###
# Test: Durchlaufen der Tibble und Anzeigen der Plots
for (i in seq_len(nrow(all_plots_DistViolin_gg))) {
print(all_plots_DistViolin_gg$plot[[i]])
}

# Kombiniere die Plots zu einem einzigen Subplot
combined_plot_gg <- wrap_plots(all_plots_DistViolin_gg$plot, ncol = 2)

# Zeige den kombinierten Plot an
print(combined_plot_gg)

# Optional: Speichern des kombinierten Plots
ggsave(filename = "combined_violin_plots_gg.png", plot = combined_plot_gg, width = 20, height = 10)

# ###ggplot###
# # Test: Durchlaufen der Tibble und Anzeigen der Plots
# for (i in seq_len(nrow(all_plots_DistViolin_gg))) {
# print(all_plots_DistViolin_gg$plot[[i]])
# }
#
# # Kombiniere die Plots zu einem einzigen Subplot
# combined_plot_gg <- wrap_plots(all_plots_DistViolin_gg$plot, ncol = 2)
#
# # Zeige den kombinierten Plot an
# print(combined_plot_gg)
#
# # Optional: Speichern des kombinierten Plots
# ggsave(filename = "combined_violin_plots_gg.png", plot = combined_plot_gg, width = 20, height = 10)
#

0 comments on commit acbd9f5

Please sign in to comment.