Merge branch 'master' of https://git.flavigny.de/christian/hateimparlament
This commit is contained in:
+30
-31
@@ -20,11 +20,11 @@ find_word <- function(res, word) {
|
||||
#' add information from speaker table to a tibble containing speaker id
|
||||
#'
|
||||
#' @param tb tibble
|
||||
#' @param res tibble
|
||||
#' @param fraction_only bool
|
||||
#' @param res list of tibbles
|
||||
#' @param fraction_only if TRUE, only select fraction from the resulting joined tibble
|
||||
#'
|
||||
#' left join speaker information from res$speaker into tb.
|
||||
#' if fraction_only is TRUE, only fraction is selected from the resulting joined tibble
|
||||
#' if fraction_only
|
||||
#'
|
||||
#' @export
|
||||
join_speaker <- function(tb, res, fraction_only = F) {
|
||||
@@ -33,7 +33,7 @@ join_speaker <- function(tb, res, fraction_only = F) {
|
||||
else joined
|
||||
}
|
||||
|
||||
#' lookup table for party colors
|
||||
#' lookup table for official party colors
|
||||
#'
|
||||
#' @export
|
||||
party_colors <- c(
|
||||
@@ -51,27 +51,27 @@ party_order <- factor(c("Fraktionslos", "AfD&Fraktionslos",
|
||||
"DIE LINKE", "BÜNDNIS 90 / DIE GRÜNEN", "SPD", "CDU/CSU",
|
||||
"FDP", "AfD", NA_character_))
|
||||
|
||||
#' plot data depending on fractions in a standardized, configurable way
|
||||
#' Bar chart visualizing fraction based data
|
||||
#'
|
||||
#' Can be configured to also visualize data not related to fractions.
|
||||
#'
|
||||
#' @param tb tibble
|
||||
#' @param x_variable column in tb
|
||||
#' @param y_variable column in tb
|
||||
#' @param fill column in tb
|
||||
#' @param title char
|
||||
#' @param xlab char
|
||||
#' @param ylab char
|
||||
#' @param filllab char
|
||||
#' @param flipped bool
|
||||
#' @param position char
|
||||
#' @param reorder bool
|
||||
#' @param x_variable column in tb, default is fraction
|
||||
#' @param y_variable column in tb, default is n
|
||||
#' @param fill column in tb, default is fraction
|
||||
#' @param title plot title
|
||||
#' @param xlab label for x axis, default is fraction
|
||||
#' @param ylab label for y axis, default is n
|
||||
#' @param filllab default is 'Fraction'
|
||||
#' @param flipped if TRUE draw bars horizontally, else vertically. Default is TRUE
|
||||
#' @param position default is 'dodge'
|
||||
#' @param reorder Either reorder fraction factor by variable value or reorder fraction factor by party seat order in parliament (default).
|
||||
#'
|
||||
#' plot data from tb in the following way: for each item in x_variable show the corresponding value in y_variable.
|
||||
#' Then color the plot depending on the fill value
|
||||
#' Give the plot a title, an x-label xlab as well as an y-label ylab
|
||||
#' Color the legend according to filllab
|
||||
#' Setting flipped to TRUE makes the bars horizontal
|
||||
#' Improve positioning details according to position
|
||||
#' and finally reorder x_variable (default ist to order fractions according to seat order)
|
||||
#' Then color the plot depending on the fill value.
|
||||
#' Give the plot a title and a label for x-axis and y-axis,
|
||||
#' color the legend according to filllab and finally
|
||||
#' improve positioning details according to position
|
||||
#'
|
||||
#' @export
|
||||
bar_plot_fractions <- function(tb,
|
||||
@@ -116,16 +116,15 @@ bar_plot_fractions <- function(tb,
|
||||
if (flipped) plt + coord_flip() else plt
|
||||
}
|
||||
|
||||
#' Counts how many talks do match a given pattern and summarises by date
|
||||
#'
|
||||
#' @param res tibble
|
||||
#' @param patterns char list
|
||||
#' @param name char ? what is name needed for??
|
||||
#' @param tidy bool, default F
|
||||
#'
|
||||
#' shorter summary if tidy=F
|
||||
#' if tidy is set to T, the resulting tibble is tidy
|
||||
#'
|
||||
#' Word usage summarised by date
|
||||
#'
|
||||
#' Counts how many talks do match a given pattern and summarises by date.
|
||||
#'
|
||||
#' @param res List of Tibbles to be analysed.
|
||||
#' @param patterns Words to look up.
|
||||
#' @param name ?
|
||||
#' @param tidy default is FALSE.
|
||||
#'
|
||||
#' @export
|
||||
word_usage_by_date <- function(res, patterns, name, tidy=F) {
|
||||
tb <- res$talks
|
||||
|
||||
@@ -205,13 +205,11 @@ parse_speakerlist <- function(speakerliste_xml) {
|
||||
rolle_lang = d["rolle_lang",])
|
||||
}
|
||||
|
||||
#' Write the parsed and repaired results into a csv file to make loading and developing faster and easier
|
||||
#' Write the parsed and repaired results into separate csv files
|
||||
#'
|
||||
#' @param tables tibble list
|
||||
#' @param path char
|
||||
#' @param create bool
|
||||
#'
|
||||
#' if create is set to TRUE, the directory given in path is created
|
||||
#' @param tables list of tables to convert into a csv files.
|
||||
#' @param path where to put the csv files.
|
||||
#' @param create set TRUE if the path does not exist yet and you want to create it
|
||||
#'
|
||||
#' @export
|
||||
write_to_csv <- function(tables, path="data/csv/", create=F) {
|
||||
@@ -223,11 +221,12 @@ write_to_csv <- function(tables, path="data/csv/", create=F) {
|
||||
write.table(tables$applause, str_c(path, "applause.csv"))
|
||||
}
|
||||
|
||||
#' Read the needed tables for developing from a csv file.
|
||||
#'
|
||||
#' @param path char
|
||||
#'
|
||||
#' Reading the tables from a csv is way faster than reading and repairing the data every single time
|
||||
|
||||
#' create a tibble from the csv file
|
||||
#'
|
||||
#' @param path directory to read files from
|
||||
#'
|
||||
#' reading the tables from a csv is way faster than reading and repairing the data every single time
|
||||
#'
|
||||
#' @export
|
||||
read_from_csv <- function(path="data/csv/") {
|
||||
|
||||
Reference in New Issue
Block a user