An R package to analyze the parliamentary records of the 19th legislative period of the Bundestag, the German parliament.
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

86 строки
2.2KB

  1. ---
  2. title: "explicittopic"
  3. output: rmarkdown::html_vignette
  4. vignette: >
  5. %\VignetteIndexEntry{explicittopic}
  6. %\VignetteEngine{knitr::rmarkdown}
  7. %\VignetteEncoding{UTF-8}
  8. ---
  9. ```{r, include = FALSE}
  10. knitr::opts_chunk$set(
  11. collapse = TRUE,
  12. comment = "#>"
  13. )
  14. ```
  15. ```{r setup}
  16. library(hateimparlament)
  17. library(dplyr)
  18. library(ggplot2)
  19. library(stringr)
  20. library(tidyr)
  21. ```
  22. ## Preparation of data
  23. First, you need to download all records of the current legislative period.
  24. ```r
  25. fetch_all("../inst/records/") # path to directory where records should be stored
  26. ```
  27. Second, those `.xml` files, need to be parsed into `R` `tibbles`. This is accomplished by:
  28. ```r
  29. read_all("../inst/records/") %>% repair() -> res
  30. ```
  31. We also used `repair` to fix a bunch of formatting issues in the records and unpacked
  32. the result into more descriptive variables.
  33. For development purposes, we load the tables from csv files.
  34. ```{r}
  35. res <- read_from_csv('../inst/csv/')
  36. ```
  37. and unpack our tibbles
  38. ```{r}
  39. comments <- res$comments
  40. speeches <- res$speeches
  41. speaker <- res$speaker
  42. talks <- res$talks
  43. ```
  44. ## Analysis
  45. Now we can start analysing our parsed dataset:
  46. ### Counting the occurences of a given word:
  47. ```{r, fig.width=7}
  48. find_word(res, "Kohleausstieg") %>%
  49. filter(occurences > 0) %>%
  50. join_speaker(res) %>%
  51. select(content, fraction) %>%
  52. filter(!is.na(fraction)) %>%
  53. group_by(fraction) %>%
  54. summarize(n = n()) %>%
  55. arrange(desc(n)) %>%
  56. bar_plot_fractions(title = "Parties using the word 'Kohleausstieg' the most (absolutely)",
  57. ylab = "Number of uses of 'Kohleausstieg'",
  58. flipped = F)
  59. ```
  60. ### When are which topics discussed the most?
  61. ```{r, fig.width=7}
  62. pandemic_pattern <- "(?i)virus|corona|covid|lockdown"
  63. climate_pattern <- "(?i)klimawandel|erderwärmung|co2|treibhaus|methan|kyoto-protokoll|klimaabkommen"
  64. pension_pattern <- "(?i)rente|pension|altersarmut"
  65. word_usage_by_date(res, c(pandemic = pandemic_pattern,
  66. climate = climate_pattern,
  67. pension = pension_pattern)) %>%
  68. ggplot(aes(x = date, y = count, color = pattern)) +
  69. xlab("date of session") +
  70. ylab("occurence of word per session") +
  71. labs(color = "Topic") +
  72. geom_point()
  73. ```