tests/testthat/test-bar_plot.R

context("bar_plot")


test_that("bar_plot works", {

  g = bar_plot(mtcars, "cyl", "1")
  expect_equal(g$data$x, c(4, 6, 8))
  expect_equal(g$data$y, c(11, 7, 14))

  g = bar_plot(mtcars, "cyl", "1", "am", position = "fill")
  expect_equal(nrow(g$data), 6)

  g = bar_plot(mtcars, "cyl", "1", "am", label_pos = "top")
  expect_equal(nrow(g$data), 6)

  g = bar_plot(mtcars, "cyl", "1", position = "fill")
  expect_equal(g$data$y, c(1, 1, 1))

  g = bar_plot(mtcars, "factor(cyl)", "1", coord_flip = TRUE)
  expect_equal(g$data$x, factor(c(4, 6, 8), c(8, 6, 4)))
  expect_equal(g$data$y, c(11, 7, 14))

  g = bar_plot(mtcars, "cyl", "1", coord_flip = TRUE)
  expect_equal(g$data$x, c(4, 6, 8))
  expect_equal(g$data$y, c(11, 7, 14))


})
wkostelecki/ezplot documentation built on Feb. 1, 2024, 10:58 p.m.