Skip to content

Instantly share code, notes, and snippets.

@kkroesch
Last active September 12, 2024 14:33
Show Gist options
  • Save kkroesch/843397304001878633a507472cd9e66a to your computer and use it in GitHub Desktop.
Save kkroesch/843397304001878633a507472cd9e66a to your computer and use it in GitHub Desktop.
Sonntagsfrage
# Installiere ggplot2 und scales, falls noch nicht installiert
# install.packages("ggplot2")
# install.packages("scales")
library(ggplot2)
library(scales)
# Erstelle den Datensatz
partei_list = c("SPD", "CDU", "Grüne", "FDP", "AfD", "Linke", "BSW", "Sonstige")
# Definiere die Parteifarben
parteifarben <- c("SPD" = "#EB001F", "CDU" = "#000000", "Grüne" = "#64A12D",
"FDP" = "#FFED00", "AfD" = "#009EE0", "Linke" = "#BE3075",
"BSW" = "#FFB366", "Sonstige" = "#AAAAAA")
parteien <- data.frame(
Partei = factor(partei_list, levels = partei_list),
Umfragewerte = c(15, 33, 11, 4, 17, 3, 8, 9)
)
# Erstelle das Säulendiagramm
ggplot(parteien, aes(x = Partei, y = Umfragewerte, fill = Partei)) +
geom_bar(stat = "identity") +
geom_text(aes(label = Umfragewerte), vjust = -0.5, size = 5) +
scale_fill_manual(values = parteifarben) +
theme_minimal() +
labs(title = "Sonntagsfrage",
x = "",
y = "") +
theme(axis.text.x = element_text(angle = 0, hjust = 0.5), # Zentriere den Text
plot.title = element_text(hjust = 0.5), # Zentriere den Titel
legend.position = "none", # Legende entfernen
panel.grid.major.x = element_blank(), # Senkrechte Gitterlinien entfernen
panel.grid.minor.x = element_blank()) # Kleinere senkrechte Gitterlinien entfernen
@kkroesch
Copy link
Author

parteien_umfrage

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment