An R package to analyze the parliamentary records of the 19th legislative period of the Bundestag, the German parliament.
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

51 řádky
1.4KB

  1. #' @export
  2. find_word <- function(res, word) {
  3. talks <- res$talks
  4. mutate(talks, occurences = sapply(str_match_all(talks$content, regex(word, ignore_case = TRUE)),
  5. nrow))
  6. }
  7. #' @export
  8. join_redner <- function(tb, res, fraktion_only = F) {
  9. joined <- left_join(tb, res$redner, by=c("redner" = "id"))
  10. if (fraktion_only) select(joined, "fraktion")
  11. else joined
  12. }
  13. party_colors <- c(
  14. SPD="#DF0B25",
  15. "CDU/CSU"="#000000",
  16. AfD="#1A9FDD",
  17. "AfD&Fraktionslos"="#1A9FDD",
  18. "DIE LINKE"="#BC3475",
  19. "BÜNDNIS 90 / DIE GRÜNEN"="#4A932B",
  20. FDP="#FEEB34",
  21. Fraktionslos="#FEEB34"
  22. )
  23. #' @export
  24. bar_plot_fraktionen <- function(tb) {
  25. ggplot(tb, aes(x = reorder(fraktion, -n), y = n, fill = fraktion)) +
  26. scale_fill_manual(values = party_colors) +
  27. geom_bar(stat = "identity")
  28. }
  29. # Counts how many talks do match a given pattern and summarises by date
  30. #
  31. #' @export
  32. word_usage_by_date <- function(res, patterns, name, tidy=F) {
  33. tb <- res$talks
  34. nms <- names(patterns)
  35. for (i in seq_along(patterns)) {
  36. if (!is.null(nms)) name <- nms[[i]]
  37. else name <- patterns[[i]]
  38. tb <- mutate(tb, {{name}} := str_count(content, patterns[[i]]))
  39. }
  40. left_join(tb, res$reden, by=c("rede_id" = "id")) %>%
  41. group_by(date) %>%
  42. summarize(across(where(is.numeric), sum)) %>%
  43. arrange(date) -> tb
  44. if (!tidy) pivot_longer(tb, where(is.numeric) , names_to = "pattern", values_to="count")
  45. else tb
  46. }