tests/testthat/test-ggscatter.R

context("ggscatter")

test_that("ggscatter works when there is spaces in variable names", {
  data("mtcars")
  df <- mtcars[, c("wt", "mpg")]
  colnames(df) <- c("Dimension 1", "Dimension 2")
  p <- ggscatter(df, x = "Dimension 1", y = "Dimension 2" )
  p_build <- ggplot2::ggplot_build(p)
  df_build <- p_build$data[[1]]
  expect_equal(df$`Dimension 1`, df_build$x)
})


test_that("ggscatter can handle non-standard column names when ggpubr.parse_aes global option is set to FALSE (#229)", {
  data("mtcars")
  df <- mtcars[, c("wt", "mpg")]
  colnames(df) <- c("A-A", "B-B")

  old_options <- options(ggpubr.parse_aes = FALSE)
  p <- ggscatter(df, x = "A-A", y = "B-B" )
  options(old_options)
  p_build <- ggplot2::ggplot_build(p)
  df_build <- p_build$data[[1]]
  expect_equal(df$`A-A`, df_build$x)
})

Try the ggpubr package in your browser

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

ggpubr documentation built on Feb. 16, 2023, 7:18 p.m.