Skip to content

Commit 00f6516

Browse files
committed
move scales to separate file, document functions
1 parent e4b641d commit 00f6516

3 files changed

Lines changed: 133 additions & 71 deletions

File tree

R/geom_errors.R

Lines changed: 0 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -147,74 +147,3 @@ MakeGeomErrors <- function() ggplot2::ggproto(
147147
grob
148148
}
149149
)
150-
151-
# registered in .onLoad()
152-
scale_type.errors <- function(x) {
153-
if (!"errors" %in% .packages())
154-
stop("Variable of class 'errors' found, but 'errors' package is not attached.\n",
155-
" Please, attach it using 'library(errors)' to properly show scales with errors.")
156-
c("errors", "continuous")
157-
}
158-
159-
#' @export
160-
scale_x_errors <- function(...) {
161-
make_scale_errors(ggplot2::scale_x_continuous(...))
162-
}
163-
164-
#' @export
165-
scale_y_errors <- function(...) {
166-
make_scale_errors(ggplot2::scale_y_continuous(...))
167-
}
168-
169-
#' @export
170-
scale_colour_errors <- function(...) {
171-
make_scale_errors(ggplot2::scale_colour_continuous(...))
172-
}
173-
174-
#' @export
175-
scale_color_errors <- scale_colour_errors
176-
177-
#' @export
178-
scale_fill_errors <- function(...) {
179-
make_scale_errors(ggplot2::scale_fill_continuous(...))
180-
}
181-
182-
#' @export
183-
scale_alpha_errors <- function(...) {
184-
make_scale_errors(ggplot2::scale_alpha(...))
185-
}
186-
187-
#' @export
188-
scale_size_errors <- function(...) {
189-
make_scale_errors(ggplot2::scale_size(...))
190-
}
191-
192-
#' @export
193-
scale_size_area_errors <- function(...) {
194-
make_scale_errors(ggplot2::scale_size_area(...))
195-
}
196-
197-
#' @export
198-
scale_radius_errors <- function(...) {
199-
make_scale_errors(ggplot2::scale_radius(...))
200-
}
201-
202-
#' @export
203-
scale_linewidth_errors <- function(...) {
204-
make_scale_errors(ggplot2::scale_linewidth(...))
205-
}
206-
207-
make_scale_errors <- function(parent) {
208-
if (!requireNamespace("ggplot2", quietly=TRUE))
209-
stop("package 'ggplot2' is required for this functionality", call.=FALSE)
210-
211-
ggplot2::ggproto(
212-
paste0(class(parent)[1], "Errors"),
213-
parent,
214-
215-
map = function(self, x, limits = self$get_limits()) {
216-
# remove errors for comparisons
217-
ggplot2::ggproto_parent(parent, self)$map(.v(x), limits)
218-
}
219-
)
220-
}

R/scale_errors.R

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
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+
}

man/scale_errors.Rd

Lines changed: 42 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)