@@ -9,6 +9,48 @@ test_that("Data is ordered by x", {
99 expect_equal(layer_data(ps )[c(" x" , " y" )], df [order(df $ x ), ])
1010})
1111
12+ test_that(" Default smoothing methods for small and large data sets work" , {
13+ # test small data set
14+ set.seed(6531 )
15+ x <- rnorm(10 )
16+ df <- data.frame (
17+ x = x ,
18+ y = x ^ 2 + 0.5 * rnorm(10 )
19+ )
20+
21+ m <- loess(y ~ x , data = df , span = 0.75 )
22+ range <- range(df $ x , na.rm = TRUE )
23+ xseq <- seq(range [1 ], range [2 ], length.out = 80 )
24+ out <- predict(m , data.frame (x = xseq ))
25+ p <- ggplot(df , aes(x , y )) + geom_smooth()
26+
27+ expect_message(
28+ plot_data <- layer_data(p ),
29+ " method = 'loess' and formula 'y ~ x'"
30+ )
31+ expect_equal(plot_data $ y , as.numeric(out ))
32+
33+ # test large data set
34+ x <- rnorm(1001 ) # 1000 is the cutoff point for gam
35+ df <- data.frame (
36+ x = x ,
37+ y = x ^ 2 + 0.5 * rnorm(1001 )
38+ )
39+
40+ m <- mgcv :: gam(y ~ s(x , bs = " cs" ), data = df )
41+ range <- range(df $ x , na.rm = TRUE )
42+ xseq <- seq(range [1 ], range [2 ], length.out = 80 )
43+ out <- predict(m , data.frame (x = xseq ))
44+ p <- ggplot(df , aes(x , y )) + geom_smooth()
45+
46+ expect_message(
47+ plot_data <- layer_data(p ),
48+ " method = 'gam' and formula 'y ~ s\\ (x, bs = \" cs\"\\ )"
49+ )
50+ expect_equal(plot_data $ y , as.numeric(out ))
51+
52+ })
53+
1254# Visual tests ------------------------------------------------------------
1355
1456test_that(" geom_smooth() works with alternative stats" , {
0 commit comments