Replace top3 plot with plotly

This commit is contained in:
2026-02-07 11:31:14 +01:00
parent 10d0a9ad05
commit fdf2cf8331

View File

@@ -232,57 +232,35 @@ server <- function(input, output, session) {
year = "2024" year = "2024"
) )
req(nrow(data_tibble) > 0) 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") plot_ly(
axis.title.y = element_text( data = data_tibble,
face = "bold", x = ~factor(
family = "sans", str_wrap(Name, width = 15),
# Fügen Sie hier einen Abstand nach RECHTS hinzu levels = str_wrap(Name[order(-Erfasst)], width = 15)
margin = margin(r = 15) # r = right (rechts) in Pixeln
), ),
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 = "<br><br><b>Straftat<b>",
tickangle = 0,
ticklabeloverflow = "allow"
),
yaxis = list(
title = "<b>Anzahl erfasster Fälle<b>"
),
margin = list(b = 160, r = 60, pad = 5)
) %>%
config(
staticPlot = TRUE
) )
}) })