Add styling to comparison graph
This commit is contained in:
59
server.R
59
server.R
@@ -264,8 +264,63 @@ server <- function(input, output, session) {
|
|||||||
year = currently_compared_year()
|
year = currently_compared_year()
|
||||||
)
|
)
|
||||||
|
|
||||||
ggplot(data_tibble, aes(x = Location, y = Erfasst, group = Name, fill = Name)) +
|
ggplot(data_tibble, aes(x = Erfasst, y = reorder(Location, Erfasst, FUN = sum), group = Name, fill = Name)) + #reorder macht die höchsten Werte nach oben, und sortiert nach Gesamtwert
|
||||||
geom_col(position = position_dodge(width = 0.9))
|
geom_col(position = position_dodge(width = 0.9)) +
|
||||||
|
scale_fill_brewer(palette = "Blues") +
|
||||||
|
geom_text(
|
||||||
|
# Die Text-Ästhetik soll der Wert aus der Spalte 'Erfasst' sein
|
||||||
|
aes(label = format(Erfasst, big.mark = ".", decimal.mark = ",")),
|
||||||
|
# Platzierung: Y-Wert des Textes = Wert der Spalte + Offset
|
||||||
|
# Wir verwenden den Offset, um den Text knapp über den Balken zu platzieren
|
||||||
|
# Wenn Sie den Text IN den Balken setzen möchten, setzen Sie y=Erfasst/2
|
||||||
|
position = position_dodge(width = 0.9),
|
||||||
|
hjust = -0.3, #schiebt die Zahl nach rechts
|
||||||
|
vjust = 0.5, #schiebt Zahlen mittig hinter Balken
|
||||||
|
size = 4,
|
||||||
|
fontface = "bold"
|
||||||
|
) +
|
||||||
|
labs(
|
||||||
|
title = "Polizeilich registrierte Straftaten",
|
||||||
|
x = "Anzahl erfasster Fälle",
|
||||||
|
y = NULL
|
||||||
|
) +
|
||||||
|
scale_x_continuous(expand = expansion(mult = c(0, 0.15))) +
|
||||||
|
theme_classic() + #neues theme aus ggthemes packages
|
||||||
|
# NEUE ANPASSUNG: Drehen der X-Achsen-Beschriftungen
|
||||||
|
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 = "bottom",
|
||||||
|
legend.text = element_text(size = 13),
|
||||||
|
legend.title = element_blank(),
|
||||||
|
# X-Achsen-Titel (z.B. "Straftatbestand")
|
||||||
|
axis.text.x = element_text(
|
||||||
|
vjust = 1,
|
||||||
|
hjust = 1,
|
||||||
|
size = 12
|
||||||
|
),
|
||||||
|
axis.title.x = element_text(
|
||||||
|
face = "bold",
|
||||||
|
family = "sans",
|
||||||
|
# Fügt Abstand nach OBEN hinzu
|
||||||
|
margin = margin(t = 15), # t = top (oben) in Pixeln
|
||||||
|
size = 12
|
||||||
|
),
|
||||||
|
axis.text.y = element_text(
|
||||||
|
size = 13
|
||||||
|
),
|
||||||
|
# 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
|
||||||
|
)
|
||||||
|
)
|
||||||
}, res = 100)
|
}, res = 100)
|
||||||
|
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user