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

(incomplete) update for upcoming ggplot2 version #124

Merged
merged 2 commits into from
Jan 24, 2024
Merged
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
6 changes: 4 additions & 2 deletions R/afex_plot_plotting_functions.R
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,8 @@ interaction_plot <- function(means,
plot_out <- plot_out +
ggplot2::xlab(attr(means, "x"))
}
if (!missing(legend_title)) {
mapping <- mapping[nzchar(mapping)]
if (!missing(legend_title) && length(mapping) > 0) {
legend_title <- paste(legend_title, collapse = "\n")
tmp_list <- rep(list(ggplot2::guide_legend(title = legend_title)),
length(mapping))
Expand Down Expand Up @@ -362,7 +363,8 @@ oneway_plot <- function(means,
plot_out <- plot_out +
ggplot2::xlab(attr(means, "x"))
}
if (!missing(legend_title)) {
mapping <- mapping[nzchar(mapping)]
if (!missing(legend_title) && length(mapping) > 0) {
legend_title <- paste(legend_title, collapse = "\n")
tmp_list <- rep(list(ggplot2::guide_legend(title = legend_title)),
length(mapping))
Expand Down
18 changes: 14 additions & 4 deletions tests/testthat/test-afex_plot-basics.R
Original file line number Diff line number Diff line change
Expand Up @@ -329,8 +329,13 @@ test_that("relabeling of factors and legend works", {

p2 <- afex_plot(aw, x = "noise", trace = "angle", error = "within",
legend_title = "Noise Condition")
expect_equal(p2$guides$shape$title, "Noise Condition")
expect_equal(p2$guides$linetype$title, "Noise Condition")
if (inherits(p2$guides, "Guides")) {
expect_equal(p2$guides$guides$shape$params$title, "Noise Condition")
expect_equal(p2$guides$guides$linetype$params$title, "Noise Condition")
} else {
expect_equal(p2$guides$shape$title, "Noise Condition")
expect_equal(p2$guides$linetype$title, "Noise Condition")
}
})

test_that("connecting individual points works", {
Expand Down Expand Up @@ -361,8 +366,13 @@ test_that("labels are correct in case variables are of lenth > 1", {
p2 <- afex_plot(a1, c("phase", "hour"), error = "none")
expect_match(p1$labels$x, "phase")
expect_match(p1$labels$x, "hour")
expect_match(p1$guides$shape$title, "treatment")
expect_match(p1$guides$shape$title, "gender")
if (inherits(p1$guides, "Guides")) {
expect_match(p1$guides$guides$shape$params$title, "treatment")
expect_match(p1$guides$guides$shape$params$title, "gender")
} else {
expect_match(p1$guides$shape$title, "treatment")
expect_match(p1$guides$shape$title, "gender")
}
expect_match(p2$labels$x, "phase")
expect_match(p2$labels$x, "hour")
})
Loading