fix funwithdata vignette, generalize bar plot helper

This commit is contained in:
2021-08-02 22:06:34 +02:00
parent 4fe45feec9
commit ccb0649cb9
2 changed files with 57 additions and 18 deletions
+15 -9
View File
@@ -12,22 +12,28 @@ join_redner <- function(tb, res, fraktion_only = F) {
else joined
}
#' @export
party_colors <- c(
SPD="#DF0B25",
"CDU/CSU"="#000000",
AfD="#1A9FDD",
"AfD&Fraktionslos"="#1A9FDD",
"DIE LINKE"="#BC3475",
"BÜNDNIS 90 / DIE GRÜNEN"="#4A932B",
FDP="#FEEB34",
"CDU/CSU"="#000000",
SPD="#DF0B25",
"BÜNDNIS 90 / DIE GRÜNEN"="#4A932B",
"DIE LINKE"="#BC3475",
"AfD&Fraktionslos"="#1A9FDD",
Fraktionslos="#FEEB34"
)
#' @export
bar_plot_fraktionen <- function(tb) {
ggplot(tb, aes(x = reorder(fraktion, -n), y = n, fill = fraktion)) +
scale_fill_manual(values = party_colors) +
geom_bar(stat = "identity")
bar_plot_fraktionen <- function(tb, variable, fill, title=NULL, xlab = "Fraction",
ylab="n", filllab="Fraction") {
ggplot(tb, aes(x = reorder(fraktion, -{{variable}}), y = {{variable}}, fill = {{fill}})) +
scale_fill_manual(values = party_colors) +
xlab(xlab) +
ylab(ylab) +
labs(fill = filllab) +
ggtitle(title) +
geom_bar(stat = "identity")
}
# Counts how many talks do match a given pattern and summarises by date