Skip to content

Commit

Permalink
Merge pull request #124 from teunbrand/ggplot2_3.5.0
Browse files Browse the repository at this point in the history
(incomplete) update for upcoming ggplot2 version
  • Loading branch information
singmann authored Jan 24, 2024
2 parents b6d844d + e9105b3 commit 1e3ee8d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
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")
})

0 comments on commit 1e3ee8d

Please sign in to comment.