tests/testthat/test-ggplot-violin.R

gg <- ggplot(mtcars, aes(factor(cyl), mpg)) + geom_violin()

test_that("basic geom_violin works", {
  L <- expect_doppelganger_built(gg, "violin")
  expect_equivalent(length(L$data), 1)
  tr <- L$data[[1]]
  expect_identical(tr$type, "scatter")
  expect_true(tr$fill == "toself")
  expect_false(tr$showlegend)
  expect_true(all(grepl("density", tr$text[!is.na(tr$text)])))
  expect_true(tr$hoverinfo == "text")
})


gg2 <- ggplot(mtcars, aes(factor(cyl), mpg, fill = factor(cyl))) + geom_violin()

test_that("geom_violin with fill aes works", {
  L <- expect_doppelganger_built(gg2, "violin-aes")
  expect_equivalent(length(L$data), 3)
  expect_true(L$layout$showlegend)
  expect_equivalent(sum(unlist(lapply(L$data, "[[", "showlegend"))), 3)
})

Try the plotly package in your browser

Any scripts or data that you put into this service are public.

plotly documentation built on May 29, 2024, 2:23 a.m.