fix errors from refactoring and add documentation to all remaining functions in analyze.R
This commit is contained in:
+57
-4
@@ -1,10 +1,31 @@
|
||||
#' Count number of occurences of a given word
|
||||
#'
|
||||
#' @param res tibble
|
||||
#' @param word character
|
||||
#'
|
||||
#' Add number of occurences of word to talks
|
||||
#'
|
||||
#' @export
|
||||
find_word <- function(res, word) {
|
||||
talks <- res$talks
|
||||
mutate(talks, occurences = sapply(str_match_all(talks$content, regex(word, ignore_case = TRUE)),
|
||||
nrow))
|
||||
mutate(
|
||||
talks,
|
||||
occurences = sapply(
|
||||
str_match_all(talks$content, regex(word, ignore_case = TRUE)),
|
||||
nrow
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
#' add information from speaker table to a tibble containing speaker id
|
||||
#'
|
||||
#' @param tb tibble
|
||||
#' @param res tibble
|
||||
#' @param fraction_only bool
|
||||
#'
|
||||
#' left join speaker information from res$speaker into tb.
|
||||
#' if fraction_only is TRUE, only fraction is selected from the resulting joined tibble
|
||||
#'
|
||||
#' @export
|
||||
join_speaker <- function(tb, res, fraction_only = F) {
|
||||
joined <- left_join(tb, res$speaker, by=c("speaker" = "id"))
|
||||
@@ -12,6 +33,8 @@ join_speaker <- function(tb, res, fraction_only = F) {
|
||||
else joined
|
||||
}
|
||||
|
||||
#' lookup table for party colors
|
||||
#'
|
||||
#' @export
|
||||
party_colors <- c(
|
||||
AfD="#1A9FDD",
|
||||
@@ -28,6 +51,28 @@ 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
|
||||
#'
|
||||
#' @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
|
||||
#'
|
||||
#' 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)
|
||||
#'
|
||||
#' @export
|
||||
bar_plot_fractions <- function(tb,
|
||||
x_variable = NULL, # default is fraction
|
||||
@@ -71,8 +116,16 @@ 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
|
||||
#
|
||||
#' 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
|
||||
#'
|
||||
#' @export
|
||||
word_usage_by_date <- function(res, patterns, name, tidy=F) {
|
||||
tb <- res$talks
|
||||
|
||||
Reference in New Issue
Block a user