Skip to content

Commit e847613

Browse files
committed
add errors scales so that the mapping (comparisons) works even when probabilistic comparisons are enabled
1 parent 510e7d3 commit e847613

3 files changed

Lines changed: 84 additions & 4 deletions

File tree

NAMESPACE

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,16 @@ export(errors)
6767
export(errors_max)
6868
export(errors_min)
6969
export(geom_errors)
70+
export(scale_alpha_errors)
71+
export(scale_color_errors)
72+
export(scale_colour_errors)
73+
export(scale_fill_errors)
74+
export(scale_linewidth_errors)
75+
export(scale_radius_errors)
76+
export(scale_size_area_errors)
77+
export(scale_size_errors)
78+
export(scale_x_errors)
79+
export(scale_y_errors)
7080
export(set_correl)
7181
export(set_covar)
7282
export(set_errors)

R/geom_errors.R

Lines changed: 69 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,4 +149,72 @@ MakeGeomErrors <- function() ggplot2::ggproto(
149149
)
150150

151151
# registered in .onLoad()
152-
scale_type.errors <- function(x) "continuous"
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+
}

man/geom_errors.Rd

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

0 commit comments

Comments
 (0)