ソースを参照

add rotatelab to bar_plot_fractions

genderequality-alternative
Leon Burgard 4年前
コミット
545e5c9bab
4個のファイルの変更36行の追加9行の削除
  1. +21
    -2
      R/analyze.R
  2. +5
    -2
      man/bar_plot_fractions.Rd
  3. +6
    -3
      vignettes/funwithdata.Rmd
  4. +4
    -2
      vignettes/interaction.Rmd

+ 21
- 2
R/analyze.R ファイルの表示

@@ -66,6 +66,7 @@ party_order <- factor(c("Fraktionslos", "AfD&Fraktionslos",
#' @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).
#' @param rotatelab Default is FALSE. If true turns the labels 90 degrees to the axis.
#'
#' 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.
@@ -84,7 +85,8 @@ bar_plot_fractions <- function(tb,
filllab = "Fraction",
flipped = TRUE,
position = "dodge",
reorder = FALSE) {
reorder = FALSE,
rotatelab = FALSE) {
# capture expressions in arguments
fill <- enexpr(fill)
y_variable <- enexpr(y_variable)
@@ -103,8 +105,23 @@ bar_plot_fractions <- function(tb,
else maps <- aes(x = factor(!!x_variable, levels = party_order),
y = !!y_variable,
fill = factor(!!fill, levels = party_order))
if(rotatelab){
# make a bar plot
ggplot(tb, maps) +
ggplot(tb, maps, rotate) +
scale_fill_manual(values = party_colors, na.value = "#555555") +
xlab(xlab) +
ylab(ylab) +
labs(fill = filllab) +
ggtitle(title) +
geom_bar(stat = "identity", position = position) +
theme(axis.text.x = element_text(angle = 90, vjust = 0.5, hjust=1)) ->
plt
}

else{
# make a bar plot
ggplot(tb, maps, rotate) +
scale_fill_manual(values = party_colors, na.value = "#555555") +
xlab(xlab) +
ylab(ylab) +
@@ -112,6 +129,8 @@ bar_plot_fractions <- function(tb,
ggtitle(title) +
geom_bar(stat = "identity", position = position) ->
plt
}
# if flipped == TRUE, draw bars horizontally (default TRUE)
if (flipped) plt + coord_flip() else plt
}


+ 5
- 2
man/bar_plot_fractions.Rd ファイルの表示

@@ -15,7 +15,8 @@ bar_plot_fractions(
filllab = "Fraction",
flipped = TRUE,
position = "dodge",
reorder = FALSE
reorder = FALSE,
rotatelab = FALSE
)
}
\arguments{
@@ -39,7 +40,9 @@ bar_plot_fractions(

\item{position}{default is 'dodge'}

\item{reorder}{Either reorder fraction factor by variable value or reorder fraction factor by party seat order in parliament (default).
\item{reorder}{Either reorder fraction factor by variable value or reorder fraction factor by party seat order in parliament (default).}

\item{rotatelab}{Default is FALSE. If true turns the labels 90 degrees to the axis.

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.


+ 6
- 3
vignettes/funwithdata.Rmd ファイルの表示

@@ -73,7 +73,8 @@ find_word(res, "Kohleausstieg") %>%
arrange(desc(n)) %>%
bar_plot_fractions(title = "Parties using the word 'Kohleausstieg' the most (absolutely)",
ylab = "Number of uses of 'Kohleausstieg'",
flipped = F)
flipped = F,
rotatelab = TRUE)
```

### Who gives the most speeches?
@@ -127,7 +128,8 @@ pivot_longer(tb, where(is.numeric), "by_fraction", "count") %>%
xlab = "Applauded fraction",
ylab = "Rounds of applauses",
filllab = "Applauding fraction",
flipped = FALSE)
flipped = FALSE,
rotatelab = TRUE)
```


@@ -157,7 +159,8 @@ pivot_longer(tb, where(is.numeric), "by_fraction", "count") %>%
xlab = "Commented fraction",
ylab = "Number of comments",
filllab = "Commenting fraction",
flipped = FALSE)
flipped = FALSE,
rotatelab = TRUE)
```

### When are which topics discussed the most?


+ 4
- 2
vignettes/interaction.Rmd ファイルの表示

@@ -79,7 +79,8 @@ pivot_longer(tb, where(is.numeric), "by_fraction", "count") %>%
xlab = "Applauded fraction",
ylab = "Rounds of applauses",
filllab = "Applauding fraction",
flipped = FALSE)
flipped = FALSE,
rotatelab = TRUE)
```


@@ -109,5 +110,6 @@ pivot_longer(tb, where(is.numeric), "by_fraction", "count") %>%
xlab = "Commented fraction",
ylab = "Number of comments",
filllab = "Commenting fraction",
flipped = FALSE)
flipped = FALSE,
rotatelab = TRUE)
```

読み込み中…
キャンセル
保存