/
graphics.R
62 lines (58 loc) · 2.02 KB
/
graphics.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#' Reorder an x or y axis within facets
#'
#' See \code{tidytext::\link[tidytext:reorder_within]{reorder_within}} for details.
#'
#' @name reorder_within
#' @keywords internal
#' @export
#' @importFrom tidytext reorder_within
#' @return A ggplot2 object for reordering elements within facets, used in combination with
#' \code{upstartr::\link[upstartr:scale_x_reordered]{scale_x_reordered}} or
#' \code{upstartr::\link[upstartr:scale_y_reordered]{scale_y_reordered}}
NULL
#' Passed after reorder_within to reorder x-axis along facets
#'
#' See \code{tidytext::\link[tidytext:scale_x_reordered]{scale_x_reordered}} for details.
#'
#' @name scale_x_reordered
#' @keywords internal
#' @export
#' @importFrom tidytext scale_x_reordered
#' @return A scale object to be consumed by ggplot2, used in combination with
#' \code{upstartr::\link[upstartr:reorder_within]{reorder_within}}.
NULL
#' Passed after reorder_within to reorder x-axis along facets
#'
#' See \code{tidytext::\link[tidytext:scale_y_reordered]{scale_y_reordered}} for details.
#'
#' @name scale_y_reordered
#' @keywords internal
#' @export
#' @importFrom tidytext scale_y_reordered
#' @return A scale object to be consumed by ggplot2, used in combination with
#' \code{upstartr::\link[upstartr:reorder_within]{reorder_within}}.
NULL
#' Create a continuous x-axis scale using percentages
#'
#' Convenience function to return a scale_x_continuous function using percentage labels.
#'
#' @param ... All your usual continuous x-axis scale parameters.
#'
#' @return A scale object to be consumed by ggplot2.
#'
#' @export
scale_x_percent <- function(...) {
ggplot2::scale_x_continuous(labels = scales::percent, ...)
}
#' Create a continuous y-axis scale using percentages
#'
#' Convenience function to return a scale_y_continuous function using percentage labels.
#'
#' @param ... All your usual continuous y-axis scale parameters.
#'
#' @return A scale object to be consumed by ggplot2.
#'
#' @export
scale_y_percent <- function(...) {
ggplot2::scale_y_continuous(labels = scales::percent, ...)
}