An R package to analyze the parliamentary records of the 19th legislative period of the Bundestag, the German parliament.
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

71 行
1.5KB

  1. ---
  2. title: "funwithdata"
  3. output: rmarkdown::html_vignette
  4. vignette: >
  5. %\VignetteIndexEntry{funwithdata}
  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. ```
  20. ## Preparation of data
  21. First, you need to download all records of the current legislative period.
  22. ```r
  23. fetch_all("../records/") # path to directory where records should be stored
  24. ```
  25. Second, those `.xml` files, need to be parsed into `R` `tibbles`. This is accomplished by:
  26. ```r
  27. read_all("../records/") %>% repair() -> res
  28. ```
  29. We also used `repair` to fix a bunch of formatting issues in the records and unpacked
  30. the result into more descriptive variables.
  31. For development purposes, we load the tables from csv files.
  32. ```{r}
  33. res <- read_from_csv('../csv/')
  34. ```
  35. and unpack our tibbles
  36. ```{r}
  37. comments <- res$comments
  38. reden <- res$reden
  39. redner <- res$redner
  40. talks <- res$talks
  41. ```
  42. ## Analysis
  43. Now we can start analysing our parsed dataset, e.g. find out which party gives the most talks:
  44. ```{r, fig.width=10}
  45. join_redner(reden, res) %>%
  46. group_by(fraktion) %>%
  47. summarize(n = n()) %>%
  48. arrange(n) %>%
  49. bar_plot_fraktionen()
  50. ```
  51. ### Count a word occurence
  52. ```{r, fig.width=10}
  53. find_word(res, "hitler") %>%
  54. filter(occurences > 0) %>%
  55. join_redner(res) %>%
  56. select(content, fraktion) %>%
  57. group_by(fraktion) %>%
  58. summarize(n = n()) %>%
  59. arrange(desc(n)) %>%
  60. bar_plot_fraktionen()
  61. ```