1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95
|
test_that("single-panel fixed coordinates", {
base <- ggplot(mtcars, aes(wt, mpg)) + geom_point()
l <- ggplotly(base + coord_equal())$x
expect_equal(l$layout$yaxis$scaleanchor, "x")
expect_equal(l$layout$yaxis$scaleratio, 1)
l2 <- ggplotly(base + coord_fixed(0.5))$x
expect_equal(l2$layout$yaxis$scaleanchor, "x")
expect_equal(l2$layout$yaxis$scaleratio, 0.5)
})
test_that("multi-panel fixed coordinates", {
base <- ggplot(mtcars, aes(wt, mpg)) +
geom_point()
# fixed scales
p <- base +
coord_equal() +
facet_wrap(~cyl)
l <- ggplotly(p)$x
expect_equal(l$layout$xaxis$scaleanchor, "y")
expect_equal(l$layout$xaxis$scaleratio, 1)
expect_equal(l$layout$xaxis2$scaleanchor, "y")
expect_equal(l$layout$xaxis2$scaleratio, 1)
expect_equal(l$layout$xaxis3$scaleanchor, "y")
expect_equal(l$layout$xaxis3$scaleratio, 1)
# free scales
# NOTE: ggplot2 doesn't even do the "correct" thing here, but we do!
p <- base +
coord_equal() +
facet_wrap(~cyl, scales = "free")
l <- ggplotly(p)$x
expect_equal(l$layout$yaxis$scaleanchor, "x")
expect_equal(l$layout$yaxis$scaleratio, 1)
expect_equal(l$layout$yaxis2$scaleanchor, "x2")
expect_equal(l$layout$yaxis2$scaleratio, 1)
expect_equal(l$layout$yaxis3$scaleanchor, "x3")
expect_equal(l$layout$yaxis3$scaleratio, 1)
# fixed scales (2 rows)
p <- base +
coord_equal() +
facet_wrap(~cyl, ncol = 2)
l <- ggplotly(p)$x
expect_equal(l$layout$yaxis$scaleanchor, "x")
expect_equal(l$layout$yaxis$scaleratio, 1)
expect_equal(l$layout$yaxis2$scaleanchor, "x")
expect_equal(l$layout$yaxis2$scaleratio, 1)
expect_equal(l$layout$xaxis$scaleanchor, "y2")
expect_equal(l$layout$xaxis$scaleratio, 1)
# facet_grid
p <- base +
coord_equal() +
facet_grid(~cyl)
l <- ggplotly(p)$x
expect_equal(l$layout$xaxis$scaleanchor, "y")
expect_equal(l$layout$xaxis$scaleratio, 1)
expect_equal(l$layout$xaxis2$scaleanchor, "y")
expect_equal(l$layout$xaxis2$scaleratio, 1)
expect_equal(l$layout$xaxis3$scaleanchor, "y")
expect_equal(l$layout$xaxis3$scaleratio, 1)
})
# TODO: why does this fail on Travis?
# test_that("coord_map", {
#
# nz <- map_data("nz")
# nzmap <- ggplot(nz, aes(x = long, y = lat, group = group)) +
# geom_polygon(fill = "white", colour = "black") +
# coord_map()
# l <- ggplotly(nzmap)$x
#
# expect_equal(l$layout$xaxis$scaleanchor, "y")
# expect_equal(
# l$layout$xaxis$scaleratio, 0.7023914, tolerance = 0.0001
# )
# })
|