Replace top3 plot with plotly
This commit is contained in:
76
server.R
76
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 = "<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
|
||||
)
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user