@@ -468,3 +468,67 @@ test_that("staged aesthetics are backtransformed properly (#4155)", {
468
468
# x / 2 should be 16 / 2 = 8, thus the result should be sqrt(8) on scale_x_sqrt()
469
469
expect_equal(layer_data(p )$ x , sqrt(8 ))
470
470
})
471
+
472
+ test_that(" numeric scale transforms can produce breaks" , {
473
+
474
+ test_breaks <- function (trans , limits ) {
475
+ scale <- scale_x_continuous(trans = trans )
476
+ scale $ train(scale $ transform(limits ))
477
+ view <- view_scale_primary(scale )
478
+ scale $ trans $ inverse(view $ get_breaks())
479
+ }
480
+
481
+ expect_equal(test_breaks(" asn" , limits = c(0 , 1 )),
482
+ seq(0 , 1 , by = 0.25 ))
483
+
484
+ expect_equal(test_breaks(" sqrt" , limits = c(0 , 10 )),
485
+ seq(0 , 10 , by = 2.5 ))
486
+
487
+ expect_equal(test_breaks(" atanh" , limits = c(- 0.9 , 0.9 )),
488
+ c(NA , - 0.5 , 0 , 0.5 , NA ))
489
+
490
+ # Broken, should fix on {scale}'s side
491
+ # expect_equal(test_breaks(boxcox_trans(0), limits = c(0, 10)), ...)
492
+
493
+ expect_equal(test_breaks(modulus_trans(0 ), c(- 10 , 10 )),
494
+ seq(- 10 , 10 , by = 5 ))
495
+
496
+ expect_equal(test_breaks(yj_trans(0 ), c(- 10 , 10 )),
497
+ seq(- 10 , 10 , by = 5 ))
498
+
499
+ expect_equal(test_breaks(" exp" , c(- 10 , 10 )),
500
+ seq(- 10 , 10 , by = 5 ))
501
+
502
+ expect_equal(test_breaks(" identity" , limits = c(- 10 , 10 )),
503
+ seq(- 10 , 10 , by = 5 ))
504
+
505
+ # irrational numbers, so snapshot values
506
+ expect_snapshot(test_breaks(" log" , limits = c(0.1 , 1000 )))
507
+
508
+ expect_equal(test_breaks(" log10" , limits = c(0.1 , 1000 )),
509
+ 10 ^ seq(- 1 , 3 ))
510
+
511
+ expect_equal(test_breaks(" log2" , limits = c(0.5 , 32 )),
512
+ c(0.5 , 2 , 8 , 32 ))
513
+
514
+ expect_equal(test_breaks(" log1p" , limits = c(0 , 10 )),
515
+ seq(0 , 10 , by = 2.5 ))
516
+
517
+ expect_equal(test_breaks(" pseudo_log" , limits = c(- 10 , 10 )),
518
+ seq(- 10 , 10 , by = 5 ))
519
+
520
+ expect_equal(test_breaks(" logit" , limits = c(0.001 , 0.999 )),
521
+ c(NA , 0.25 , 0.5 , 0.75 , NA ))
522
+
523
+ expect_equal(test_breaks(" probit" , limits = c(0.001 , 0.999 )),
524
+ c(NA , 0.25 , 0.5 , 0.75 , NA ))
525
+
526
+ expect_equal(test_breaks(" reciprocal" , limits = c(1 , 10 )),
527
+ c(NA , 2.5 , 5 , 7.5 , 10 ))
528
+
529
+ expect_equal(test_breaks(" reverse" , limits = c(- 10 , 10 )),
530
+ seq(- 10 , 10 , by = 5 ))
531
+
532
+ expect_equal(test_breaks(" sqrt" , limits = c(0 , 10 )),
533
+ seq(0 , 10 , by = 2.5 ))
534
+ })
0 commit comments