From 787aaf6c1228dbfc969d6528b8b3ddbe65f5d472 Mon Sep 17 00:00:00 2001 From: Emily de la Rua Date: Tue, 23 Apr 2024 18:58:49 -0400 Subject: [PATCH 1/2] Manually specify shapes within `g_lineplot` when >6 group levels exist --- R/g_lineplot.R | 5 +++++ tests/testthat/test-g_lineplot.R | 13 +++++++++++++ 2 files changed, 18 insertions(+) diff --git a/R/g_lineplot.R b/R/g_lineplot.R index e0cac947d1..b3cd77ce19 100644 --- a/R/g_lineplot.R +++ b/R/g_lineplot.R @@ -308,6 +308,11 @@ g_lineplot <- function(df, ) ) + if (nlevels(df_stats[[strata_N]]) > 6) { + p <- p + + scale_shape_manual(values = seq(15, 15 + nlevels(df_stats[[strata_N]]))) + } + if (!is.null(mid)) { # points if (grepl("p", mid_type, fixed = TRUE)) { diff --git a/tests/testthat/test-g_lineplot.R b/tests/testthat/test-g_lineplot.R index 2cacf61807..8acd4fcde4 100644 --- a/tests/testthat/test-g_lineplot.R +++ b/tests/testthat/test-g_lineplot.R @@ -50,6 +50,19 @@ testthat::test_that("g_lineplot works with cohort_id specified", { expect_snapshot_ggplot(title = "g_lineplot_cohorts", fig = g_lineplot_cohorts, width = 10, height = 8) }) +testthat::test_that("g_lineplot does not produce a warning if group_var has >6 levels", { + set.seed(1) + adlb$FACTOR7 <- as.factor(sample(1:7, nrow(adlb), replace = TRUE)) + + testthat::expect_silent(withr::with_options( + opts_partial_match_old, + g_lineplot( + adlb, + variables = control_lineplot_vars(group_var = "FACTOR7") + ) + )) +}) + testthat::test_that("control_lineplot_vars works", { testthat::expect_silent(control_lineplot_vars(group_var = NA)) From 38315ee66c8f6d924054848dcdf304d35de6b8c1 Mon Sep 17 00:00:00 2001 From: Emily de la Rua Date: Tue, 23 Apr 2024 19:08:43 -0400 Subject: [PATCH 2/2] Fix --- R/g_lineplot.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/g_lineplot.R b/R/g_lineplot.R index b3cd77ce19..b2770aee8b 100644 --- a/R/g_lineplot.R +++ b/R/g_lineplot.R @@ -308,7 +308,7 @@ g_lineplot <- function(df, ) ) - if (nlevels(df_stats[[strata_N]]) > 6) { + if (!is.null(group_var) && nlevels(df_stats[[strata_N]]) > 6) { p <- p + scale_shape_manual(values = seq(15, 15 + nlevels(df_stats[[strata_N]]))) }