|
| 1 | +#' Continuous scales for \code{errors} objects |
| 2 | +#' |
| 3 | +#' Default scales for the \code{errors} class. |
| 4 | +#' |
| 5 | +#' @param ... arguments passed on to the corresponding continuous scale |
| 6 | +#' (see the manual page for each \code{scale_{type}} for details). |
| 7 | +#' |
| 8 | +#' @name scale_errors |
| 9 | +#' @aliases NULL |
| 10 | +NULL |
| 11 | + |
| 12 | +#' @rdname scale_errors |
| 13 | +#' @export |
| 14 | +scale_x_errors <- function(...) { |
| 15 | + make_scale_errors(ggplot2::scale_x_continuous(...)) |
| 16 | +} |
| 17 | + |
| 18 | +#' @rdname scale_errors |
| 19 | +#' @export |
| 20 | +scale_y_errors <- function(...) { |
| 21 | + make_scale_errors(ggplot2::scale_y_continuous(...)) |
| 22 | +} |
| 23 | + |
| 24 | +#' @rdname scale_errors |
| 25 | +#' @export |
| 26 | +scale_colour_errors <- function(...) { |
| 27 | + make_scale_errors(ggplot2::scale_colour_continuous(...)) |
| 28 | +} |
| 29 | + |
| 30 | +#' @rdname scale_errors |
| 31 | +#' @export |
| 32 | +scale_color_errors <- scale_colour_errors |
| 33 | + |
| 34 | +#' @rdname scale_errors |
| 35 | +#' @export |
| 36 | +scale_fill_errors <- function(...) { |
| 37 | + make_scale_errors(ggplot2::scale_fill_continuous(...)) |
| 38 | +} |
| 39 | + |
| 40 | +#' @rdname scale_errors |
| 41 | +#' @export |
| 42 | +scale_alpha_errors <- function(...) { |
| 43 | + make_scale_errors(ggplot2::scale_alpha(...)) |
| 44 | +} |
| 45 | + |
| 46 | +#' @rdname scale_errors |
| 47 | +#' @export |
| 48 | +scale_size_errors <- function(...) { |
| 49 | + make_scale_errors(ggplot2::scale_size(...)) |
| 50 | +} |
| 51 | + |
| 52 | +#' @rdname scale_errors |
| 53 | +#' @export |
| 54 | +scale_size_area_errors <- function(...) { |
| 55 | + make_scale_errors(ggplot2::scale_size_area(...)) |
| 56 | +} |
| 57 | + |
| 58 | +#' @rdname scale_errors |
| 59 | +#' @export |
| 60 | +scale_radius_errors <- function(...) { |
| 61 | + make_scale_errors(ggplot2::scale_radius(...)) |
| 62 | +} |
| 63 | + |
| 64 | +#' @rdname scale_errors |
| 65 | +#' @export |
| 66 | +scale_linewidth_errors <- function(...) { |
| 67 | + make_scale_errors(ggplot2::scale_linewidth(...)) |
| 68 | +} |
| 69 | + |
| 70 | +make_scale_errors <- function(parent) { |
| 71 | + if (!requireNamespace("ggplot2", quietly=TRUE)) |
| 72 | + stop("package 'ggplot2' is required for this functionality", call.=FALSE) |
| 73 | + |
| 74 | + ggplot2::ggproto( |
| 75 | + paste0(class(parent)[1], "Errors"), |
| 76 | + parent, |
| 77 | + |
| 78 | + map = function(self, x, limits = self$get_limits()) { |
| 79 | + # remove errors for comparisons |
| 80 | + ggplot2::ggproto_parent(parent, self)$map(.v(x), limits) |
| 81 | + } |
| 82 | + ) |
| 83 | +} |
| 84 | + |
| 85 | +# registered in .onLoad() |
| 86 | +scale_type.errors <- function(x) { |
| 87 | + if (!"errors" %in% .packages()) |
| 88 | + stop("Variable of class 'errors' found, but 'errors' package is not attached.\n", |
| 89 | + " Please, attach it using 'library(errors)' to properly show scales with errors.") |
| 90 | + c("errors", "continuous") |
| 91 | +} |
0 commit comments