/
plot_cxn_interrater.R
46 lines (45 loc) · 1.82 KB
/
plot_cxn_interrater.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#' Top constructional patterns
#'
#' @description A function to generate Figure 3.1 in Rajeg (2019).
#' The figure shows the proportion of the most frequent
#' constructional patterns agreed during the interrater agreement trial.
#' @param df data frame for the plot included in the package, that is \code{top_cxn_data}.
#'
#' @return A ggplot image
#' @export
#'
#' @examples
#' plot_cxn_interrater(df = top_cxn_data)
#'
#'
#' @importFrom ggplot2 ggplot
#' @importFrom ggplot2 aes
#' @importFrom ggplot2 geom_col
#' @importFrom ggplot2 theme_bw
#' @importFrom ggplot2 labs
#' @importFrom ggplot2 scale_fill_grey
#' @importFrom ggplot2 geom_text
#' @importFrom ggplot2 position_fill
#' @importFrom stats reorder
#'
#' @references Rajeg, G. P. W. (2019). \emph{Metaphorical profiles and near-synonyms: A corpus-based study of Indonesian words for HAPPINESS}. PhD Thesis. Monash University. Melbourne, Australia. \url{https://doi.org/10.26180/5cac231a97fb1}.
plot_cxn_interrater <- function(df = NULL) {
synonyms <- dplyr::quo(synonyms)
cxn_pattern <- dplyr::quo(cxn_pattern)
ggplot2::ggplot(data = df,
ggplot2::aes(x = synonyms,
y = n,
fill = stats::reorder(cxn_pattern, -n),
group = stats::reorder(cxn_pattern, -n))) +
ggplot2::geom_col(position = "fill") +
ggplot2::theme_bw() +
ggplot2::labs(x = "Synonyms",
fill = "Constructional patterns",
y = "Proportion") +
ggplot2::scale_fill_grey(start = 0.1, end = 0.95) +
ggplot2::geom_text(ggplot2::aes(label = n),
position = ggplot2::position_fill(0.9),
colour = rep(c('white', 'black', 'black', 'black'), 3),
vjust = 1.5,
size = 2.35)
}