@@ -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+ }
0 commit comments