|
| 1 | +context("Vline") |
| 2 | +# Vertical line |
| 3 | + |
| 4 | +x1 <- seq(from=0, to=3.5, by=0.5) |
| 5 | +x2 <- x1 * 0.95 |
| 6 | +df <- data.frame("x1"=x1, "x2"=x2) |
| 7 | +gg <- ggplot(df) + geom_point(aes(x=x1, y=x2)) |
| 8 | + |
| 9 | +test_that("second trace be the vline", { |
| 10 | + gg <- gg + geom_vline(xintercept=1.1, colour="green", size=3) |
| 11 | + |
| 12 | + L <- gg2list(gg) |
| 13 | + |
| 14 | + expect_equal(length(L), 3) |
| 15 | + expect_equal(L[[2]]x[1], 1.1) |
| 16 | + expect_true(L[[2]]$y[1] <= 0) |
| 17 | + expect_true(L[[2]]$y[2] >= 3.325) |
| 18 | + expect_identical(L[[2]]$mode, "lines") |
| 19 | + expect_identical(L[[2]]$line$shape, "linear") |
| 20 | + expect_equal(L[[2]]$line$width, 3) |
| 21 | + expect_identical(L[[2]]$line$color, "rgb(0,255,0)") |
| 22 | + |
| 23 | + save_outputs(gg, "vline") |
| 24 | +}) |
| 25 | + |
| 26 | +test_that("vector yintercept results in multiple vertical lines", { |
| 27 | + gg <- gg + geom_vline(xintercept=1:2, colour="blue", size=3) |
| 28 | + |
| 29 | + L <- gg2list(gg) |
| 30 | + |
| 31 | + expect_equal(length(L), 4) |
| 32 | + expect_equal(L[[2]]x[1], 1) |
| 33 | + expect_equal(L[[3]]x[1], 2) |
| 34 | + expect_true(L[[3]]$y[1] <= 0) |
| 35 | + expect_true(L[[3]]$y[2] >= 3.325) |
| 36 | + expect_identical(L[[3]]$mode, "lines") |
| 37 | + expect_identical(L[[3]]$line$shape, "linear") |
| 38 | + expect_equal(L[[3]]$line$width, 3) |
| 39 | + expect_identical(L[[3]]$line$color, "rgb(0,0,255)") |
| 40 | + |
| 41 | + save_outputs(gg, "vline-multiple") |
| 42 | +}) |
0 commit comments