An R package to analyze the parliamentary records of the 19th legislative period of the Bundestag, the German parliament.
No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

83 líneas
1.9KB

  1. ---
  2. title: "General questions"
  3. output: rmarkdown::html_vignette
  4. vignette: >
  5. %\VignetteIndexEntry{General questions}
  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.
  32. For development purposes, we load the tables from csv files.
  33. ```{r}
  34. res <- read_from_csv('../inst/csv/')
  35. ```
  36. ## Analysis
  37. Now we can start analysing our parsed dataset:
  38. ### Which party gives the most talks?
  39. ```{r, fig.width=7}
  40. join_speaker(res$speeches, res) %>%
  41. group_by(fraction) %>%
  42. summarize(n = n()) %>%
  43. arrange(n) %>%
  44. bar_plot_fractions(title="Number of speeches given by fraction",
  45. ylab="Number of speeches")
  46. ```
  47. Note that `NA` signifies speeches given by speakers who are not members of parliament.
  48. ### Who gives the most speeches?
  49. ```{r}
  50. res$speeches %>%
  51. group_by(speaker) %>%
  52. summarize(n = n()) %>%
  53. arrange(-n) %>%
  54. left_join(res$speaker, by=c("speaker" = "id")) %>%
  55. head(10)
  56. ```
  57. ### Who talks the longest?
  58. Calculate the average character length of talks given by speakers:
  59. ```{r}
  60. res$talks %>%
  61. mutate(content_len = str_length(content)) %>%
  62. group_by(speaker) %>%
  63. summarize(avg_content_len = mean(content_len)) %>%
  64. arrange(-avg_content_len) %>%
  65. left_join(res$speaker, by=c("speaker" = "id")) %>%
  66. head(10)
  67. ```