diff --git a/server.R b/server.R index 1274a7c..f17f82e 100644 --- a/server.R +++ b/server.R @@ -232,57 +232,35 @@ server <- function(input, output, session) { year = "2024" ) req(nrow(data_tibble) > 0) - ggplotly(ggplot(data_tibble, aes(x = reorder(Name, -Erfasst), y = Erfasst, fill = Name)) + - geom_col(width = 0.7) + - scale_x_discrete( - labels = function(x) str_wrap(x, width = 15)) + - scale_fill_manual(values = c( - "#b8ecff", - "#d5f4ff", - "#e6f9ff" - )) + - geom_text( - aes(label = format(Erfasst, big.mark = ".", decimal.mark = ",")), - vjust = -0.8, # Vertikale Ausrichtung: Negativer Wert platziert Text über dem Punkt - size = 4, - fontface = "bold" - ) + - labs( - title = NULL, - x = "Straftatbestand", - y = "Anzahl erfasster Fälle" - ) + - theme_pander() + #neues theme aus ggthemes packages - theme( - plot.background = element_rect( - color = "darkgrey", # Farbe des Rahmens - linewidth = 0.4, # Dicke des Rahmens - fill = NA # Füllung: NA = transparent - ), - plot.margin = margin(t = 20, r = 20, b = 20, l = 20, unit = "pt"), - legend.position = "none", - panel.grid.major.x = element_blank(), - panel.grid.minor.x = element_blank(), # vertikale grid lines entfernen - # X-Achsen-Titel (z.B. "Straftatbestand") - axis.text.x = element_text( - angle = 0, - size = 9 - ), - axis.title.x = element_text( - face = "bold", - family = "sans", - # Fügen Sie hier einen Abstand nach OBEN hinzu - margin = margin(t = 15) # t = top (oben) in Pixeln - ), - - # Y-Achsen-Titel (z.B. "Anzahl erfasster Fälle") - axis.title.y = element_text( - face = "bold", - family = "sans", - # Fügen Sie hier einen Abstand nach RECHTS hinzu - margin = margin(r = 15) # r = right (rechts) in Pixeln - ), + + plot_ly( + data = data_tibble, + x = ~factor( + str_wrap(Name, width = 15), + levels = str_wrap(Name[order(-Erfasst)], width = 15) + ), + y = ~Erfasst, + name = "Top 3", + text = format(data_tibble$Erfasst, big.mark = ".", decimal.mark = ","), + textposition = "outside", + type = "bar", + marker = list( + color = c("#b8ecff", "#d5f4ff", "#e6f9ff") ) + ) %>% + layout( + xaxis = list( + title = "

Straftat", + tickangle = 0, + ticklabeloverflow = "allow" + ), + yaxis = list( + title = "Anzahl erfasster Fälle" + ), + margin = list(b = 160, r = 60, pad = 5) + ) %>% + config( + staticPlot = TRUE ) })