Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding Visual Expectations for Plotting Functions #572

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ Suggests:
R.rsp,
skimr,
spelling,
testthat
testthat,
vdiffr
SystemRequirements: Rendering the document template requires
pandoc (>= 2.0; https://pandoc.org) and for PDFs a TeX distribution,
such as TinyTeX (>= 0.12; https://yihui.org/tinytex/)
Expand Down
3 changes: 2 additions & 1 deletion R/apa_factorial_plot.R
Original file line number Diff line number Diff line change
Expand Up @@ -499,6 +499,7 @@ apa_factorial_plot.default <- function(
}
}
}
class(output) <- "noprint"
invisible(output)
}

Expand Down Expand Up @@ -887,7 +888,6 @@ apa_factorial_plot_single <- function(aggregated, y.values, id, dv, factors, int
, args_plot_window =args_plot_window
)
)

}


Expand Down Expand Up @@ -938,3 +938,4 @@ apa_factorial_plot.afex_aov <- function(
)
do.call("apa_factorial_plot.default", ellipsis)
}

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
490 changes: 490 additions & 0 deletions tests/testthat/_snaps/apa_plot/legacy-interface-apa-barplot.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
305 changes: 305 additions & 0 deletions tests/testthat/_snaps/apa_plot/legacy-interface-apa-beeplot.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
477 changes: 477 additions & 0 deletions tests/testthat/_snaps/apa_plot/legacy-interface-apa-lineplot.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
305 changes: 305 additions & 0 deletions tests/testthat/_snaps/apa_plot/legacy-interface-swarm-inheritance.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
140 changes: 140 additions & 0 deletions tests/testthat/test_apa_plot.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
context("Snapshot tests for apa_*plot functions")

skip_on_cran()

set.seed(43L)
palette("R4")

# suppress printing
registerS3method(genname = "print", class = "noprint", method = function(x, ...) invisible())


example_data <- expand.grid(
A = paste0("a", 1:5),
B = paste0("b", 1:3),
C = paste0("c", 1:2),
D = paste0("d", 1:4),
sid = 1:12
)
example_data$first_dv <- rnorm(12)[example_data$sid] +
rnorm(5)[example_data$A] +
rnorm(3)[example_data$B] +
rnorm(2)[example_data$C] +
rnorm(4)[example_data$D] +
rnorm(nrow(example_data))

variable_labels(example_data) <- list(
A = expression("Factor"~bold(A))
, B = expression("Factor"~bold(B))
, C = expression("Factor"~bold(C))
, D = expression("Factor"~bold(D))#
, first_dv = expression("Dependent variable"~italic(Y)[1])
)

test_that(
"Legacy interface, apa_beeplot()", {
vdiffr::expect_doppelganger(
"Legacy interface, apa_beeplot()",
apa_beeplot(
data = example_data
, dv = "first_dv"
, id = "sid"
, factors = c("A", "B")
, dispersion = wsci
, level = .99
)
)
}
)


test_that(
"Legacy interface, apa_barplot()", {
vdiffr::expect_doppelganger(
"Legacy interface, apa_barplot()",
apa_barplot(
data = example_data
, dv = "first_dv"
, factors = c("A", "B", "D")
, id = "sid"
, args_rect = list(
col = 3:5
, border = 1:3
)
, args_legend = list(
legend = letters[2:4]
)
)
)
}
)

test_that(
"Legacy interface, apa_lineplot()", {
vdiffr::expect_doppelganger(
"Legacy interface, apa_lineplot()",
apa_lineplot(
data = example_data
, dv = "first_dv"
, factors = c("A", "B", "D")
, id = "sid"
, args_lines = list(
lwd = 3:1
)
, args_points = list(
cex = 3
)
, args_x_axis = list(
cex.axis = 2
)
)
)
}
)

test_that(
"Legacy interface, apa_beeplot(), swarm inheritance", {
vdiffr::expect_doppelganger(
"Legacy interface, swarm inheritance",
apa_beeplot(
data = example_data, dv = "first_dv", id = "sid", factors = c("A", "B")
, args_points = list(
cex = seq(1, 2, length = 3)
, bg = 2:4
, pch = 23:25
, col = "skyblue4"
, lwd = 3
)
)
)
}
)

# More complex designs ----
test_that(
"Legacy interface, apa_beeplot(), three factors", {
vdiffr::expect_doppelganger(
"Legacy interface, apa_beeplot(), three factors",
apa_beeplot(data = example_data, dv = "first_dv", id = "sid", factors = c("A", "B", "C"))
)
}
)

test_that(
"Legacy interface, apa_barplot(), three factors", {
vdiffr::expect_doppelganger(
"Legacy interface, apa_barplot(), three factors",
apa_barplot(data = example_data, dv = "first_dv", id = "sid", factors = c("A", "B", "C"))

)
}
)

test_that(
"Legacy interface, apa_lineplot(), three factors", {
vdiffr::expect_doppelganger(
"Legacy interface, apa_lineplot(), three factors",
apa_lineplot(data = example_data, dv = "first_dv", id = "sid", factors = c("A", "B", "C"))
)
}
)
Loading