File: test-geom-errorbar-flipped-aes.R

package info (click to toggle)
r-cran-plotly 4.10.4%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 30,636 kB
  • sloc: javascript: 195,272; sh: 24; makefile: 6
file content (28 lines) | stat: -rw-r--r-- 1,111 bytes parent folder | download | duplicates (2)
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


test_that("geom_errobar is rendered with flipped aes", {
  
  df <- dplyr::group_by(iris, Species)
  df <- dplyr::summarise_if(df, is.numeric, list(m = mean, q1 = ~ quantile(.x, .25), q3 = ~ quantile(.x, .75)))
  gp <- ggplot(df, aes(y = Species, xmin = Sepal.Width_q1, xmax = Sepal.Width_q3)) +
    geom_errorbar()
  
  L <- plotly_build(gp)
  
  # Tests
  # errobar is rendered
  expect_doppelganger(L, "errobar-flipped-aes")
  # xmin and xmax equal to ggplot 
  expect_equivalent(L[["x"]][["data"]][[1]][["x"]] + L[["x"]][["data"]][[1]][["error_x"]][["array"]],
                    ggplot_build(gp)$data[[1]]$xmax)
  
  expect_equivalent(L[["x"]][["data"]][[1]][["x"]] - L[["x"]][["data"]][[1]][["error_x"]][["arrayminus"]],
                    ggplot_build(gp)$data[[1]]$xmin)
  # xmin and xmax equal to data
  expect_equivalent(L[["x"]][["data"]][[1]][["x"]] + L[["x"]][["data"]][[1]][["error_x"]][["array"]],
                    df$Sepal.Width_q3)
  
  expect_equivalent(L[["x"]][["data"]][[1]][["x"]] - L[["x"]][["data"]][[1]][["error_x"]][["arrayminus"]],
                    df$Sepal.Width_q1)
  
})