juliasilge / tidytext
Showing 1 of 6 files from the diff.

@@ -14,7 +14,9 @@
Loading
14 14
#' variables.
15 15
#' @param fun Function to perform within each subset to determine the resulting
16 16
#' ordering. By default, mean.
17 -
#' @param sep Separator to distinguish the two. You may want to set this
17 +
#' @param labels Function to transform the labels of
18 +
#' [ggplot2::scale_x_discrete()], by default `reorder_func`.
19 +
#' @param sep Separator to distinguish `by` and `within`. You may want to set this
18 20
#' manually if ___ can exist within one of your labels.
19 21
#' @param ... In \code{reorder_within} arguments passed on to
20 22
#' \code{\link{reorder}}. In the scale functions, extra arguments passed on to
@@ -49,6 +51,7 @@
Loading
49 51
#'   scale_x_reordered() +
50 52
#'   facet_wrap(vs ~ am, scales = "free_x")
51 53
#'
54 +
#' @importFrom lifecycle deprecated
52 55
#' @export
53 56
reorder_within <- function(x, by, within, fun = mean, sep = "___", ...) {
54 57
  if (!is.list(within)) {
@@ -62,15 +65,39 @@
Loading
62 65
63 66
#' @rdname reorder_within
64 67
#' @export
65 -
scale_x_reordered <- function(..., sep = "___") {
66 -
  reg <- paste0(sep, ".+$")
67 -
  ggplot2::scale_x_discrete(labels = function(x) gsub(reg, "", x), ...)
68 +
scale_x_reordered <- function(..., labels = reorder_func, sep = deprecated()) {
69 +
70 +
  if (lifecycle::is_present(sep)) {
71 +
    lifecycle::deprecate_soft(
72 +
      "0.3.3",
73 +
      "scale_x_reordered(sep = )",
74 +
      "reorder_func(sep = )"
75 +
    )
76 +
  }
77 +
78 +
  ggplot2::scale_x_discrete(labels = labels, ...)
68 79
}
69 80
70 81
71 82
#' @rdname reorder_within
72 83
#' @export
73 -
scale_y_reordered <- function(..., sep = "___") {
84 +
scale_y_reordered <- function(..., labels = reorder_func, sep = deprecated()) {
85 +
86 +
  if (lifecycle::is_present(sep)) {
87 +
    lifecycle::deprecate_soft(
88 +
      "0.3.3",
89 +
      "scale_y_reordered(sep = )",
90 +
      "reorder_func(sep = )"
91 +
    )
92 +
  }
93 +
94 +
  ggplot2::scale_y_discrete(labels = labels, ...)
95 +
}
96 +
97 +
#' @rdname reorder_within
98 +
#' @export
99 +
reorder_func <- function(x, sep = "___") {
74 100
  reg <- paste0(sep, ".+$")
75 -
  ggplot2::scale_y_discrete(labels = function(x) gsub(reg, "", x), ...)
101 +
  gsub(reg, "", x)
76 102
}
103 +
Files Coverage
R 81.70%
Project Totals (19 files) 81.70%
1
comment: false
2

3
coverage:
4
  status:
5
    project:
6
      default:
7
        target: auto
8
        threshold: 1%
9
    patch:
10
      default:
11
        target: auto
12
        threshold: 1%
Sunburst
The inner-most circle is the entire project, moving away from the center are folders then, finally, a single file. The size and color of each slice is representing the number of statements and the coverage, respectively.
Icicle
The top section represents the entire project. Proceeding with folders and finally individual files. The size and color of each slice is representing the number of statements and the coverage, respectively.
Grid
Each block represents a single file in the project. The size and color of each block is represented by the number of statements and the coverage, respectively.
Loading