tests/testthat/test-table_themes.R

library(dplyr)
library(tibble)

get_tb <- function() {
  mtcars %>%
    group_by(cyl) %>%
    summarize(wt = mean(wt), mpg = mean(mpg)) %>%
    ungroup() %>%
    mutate(
      wt = sprintf("%.2f", wt),
      mpg = sprintf("%.1f", mpg)
    )
}

test_that("ttheme_set works as expected but is not baked into objects", {
  tb <- get_tb()
  df <- tibble(x = 5.45, y = 34, tb = list(tb))
  ttheme_set()
  p1 <- ggplot(mtcars, aes(wt, mpg, colour = factor(cyl))) +
    geom_point() +
    geom_table(data = df, aes(x = x, y = y, label = tb))
  ttheme_set(ttheme_gtbw)
  p2 <- ggplot(mtcars, aes(wt, mpg, colour = factor(cyl))) +
    geom_point() +
    geom_table(data = df, aes(x = x, y = y, label = tb))
  expect_equal(p1, p2)
})

Try the ggplot2.utils package in your browser

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

ggplot2.utils documentation built on June 26, 2024, 1:06 a.m.