@@ -10,7 +10,26 @@ test_that("a warning is issued when there is more than one z per x+y", {
10
10
test_that(" contouring sparse data results in a warning" , {
11
11
tbl <- data_frame(x = c(1 , 27 , 32 ), y = c(1 , 1 , 30 ), z = c(1 , 2 , 3 ))
12
12
p <- ggplot(tbl , aes(x , y , z = z )) + geom_contour()
13
- expect_warning(ggplot_build(p ), " Number of x coordinates must match" )
13
+ expect_warning(ggplot_build(p ), " Zero contours were generated" )
14
+ })
15
+
16
+ test_that(" contouring irregularly spaced data works" , {
17
+ tbl <- expand.grid(x = c(1 , 10 , 100 , 1000 ), y = 1 : 3 )
18
+ tbl $ z <- 1
19
+ tbl [c(6 , 7 ), ]$ z <- 10
20
+ p <- ggplot(tbl , aes(x , y , z = z )) + geom_contour(breaks = c(4 , 8 ))
21
+
22
+ # we're testing for set equality here because contour lines are not
23
+ # guaranteed to start and end at the same point on all architectures
24
+ d <- layer_data(p )
25
+ d4 <- d [d $ level == 4 ,]
26
+ expect_equal(nrow(d4 ), 7 )
27
+ expect_setequal(d4 $ x , c(4 , 10 , 100 , 700 ))
28
+ expect_setequal(d4 $ y , c(2 , 8 / 3 , 4 / 3 ))
29
+ d8 <- d [d $ level == 8 ,]
30
+ expect_equal(nrow(d8 ), 7 )
31
+ expect_setequal(d8 $ x , c(8 , 10 , 100 , 300 ))
32
+ expect_setequal(d8 $ y , c(2 , 20 / 9 , 16 / 9 ))
14
33
})
15
34
16
35
test_that(" contour breaks can be set manually and by bins and binwidth" , {
0 commit comments