tests/testthat/test-plot_bar.R

test_that("plot_bar", {

  # build example coin
  coin <- build_example_coin(quietly = TRUE)

  # bar plot of CO2 by GDP per capita group
  plt <- plot_bar(coin, dset = "Raw", iCode = "CO2",
           by_group = "GDPpc_group", axes_label = "iName")
  expect_s3_class(plt, "ggplot")

  iData <- get_data(coin, "Raw")
  expect_setequal(plt$data$CO2, iData$CO2)

  # stack
  plt <- plot_bar(coin, dset = "Aggregated", iCode = "Conn", stack_children = TRUE,
                  axes_label = "iName")
  expect_s3_class(plt, "ggplot")
  iData <- get_data(coin, "Aggregated")
  expect_setequal(unique(plt$data$Component),
                  na.omit(coin$Meta$Ind$iCode[coin$Meta$Ind$Parent == "Conn"]))

  # no group
  plt <- plot_bar(coin, dset = "Raw", iCode = "CO2")
  expect_s3_class(plt, "ggplot")

})

Try the COINr package in your browser

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

COINr documentation built on Oct. 9, 2023, 5:07 p.m.