From f2aa8dd086dd699499e3a30099552a18aaadb35f Mon Sep 17 00:00:00 2001 From: Stella Banjo Date: Tue, 1 Nov 2022 12:12:40 +0000 Subject: [PATCH 1/8] added legend to g_step plot --- R/g_step.R | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/R/g_step.R b/R/g_step.R index a4efa855e2..315434e443 100644 --- a/R/g_step.R +++ b/R/g_step.R @@ -108,12 +108,11 @@ g_step <- function(df, ) } p <- p + ggplot2::geom_line( - ggplot2::aes_string(y = "y"), - color = est$col, + ggplot2::aes_string(y = "y", color = "est$col"), linetype = est$lty ) - p <- p + ggplot2::labs(x = attrs$biomarker, y = attrs$estimate) + p <- p + ggplot2::labs(x = attrs$biomarker, y = attrs$estimate, color = "Legend") if (use_percentile) { p <- p + ggplot2::scale_x_continuous(labels = scales::percent) } From 45d63c938e79b7bf425c24e5aedee2660d8a8694 Mon Sep 17 00:00:00 2001 From: Melkiades Date: Tue, 8 Nov 2022 12:27:15 +0100 Subject: [PATCH 2/8] fixing the legend --- R/g_step.R | 29 +++++++++++++++++++---------- man/g_step.Rd | 2 +- tern.Rproj | 1 + 3 files changed, 21 insertions(+), 11 deletions(-) diff --git a/R/g_step.R b/R/g_step.R index 315434e443..4d625243a0 100644 --- a/R/g_step.R +++ b/R/g_step.R @@ -77,7 +77,7 @@ #' g_step(step_data) g_step <- function(df, use_percentile = "Percentile Center" %in% names(df), - est = list(col = "black", lty = 1), + est = list(col = "blue", lty = 1), ci_ribbon = list(fill = getOption("ggplot2.discrete.colour")[1], alpha = 0.5), col = getOption("ggplot2.discrete.colour")) { checkmate::assert_tibble(df) @@ -90,7 +90,10 @@ g_step <- function(df, df$x <- df[[x_var]] attrs <- attributes(df) df$y <- df[[attrs$estimate]] - p <- ggplot2::ggplot(df, ggplot2::aes_string(x = "x")) + + legend_names <- c("Estimate", "CI 95%") + + p <- ggplot2::ggplot(df, ggplot2::aes_string(x = "x", y = "y")) if (!is.null(col)) { p <- p + @@ -102,17 +105,23 @@ g_step <- function(df, ci_ribbon$fill <- "lightblue" } p <- p + ggplot2::geom_ribbon( - ggplot2::aes_string(ymin = "ci_lower", ymax = "ci_upper"), - fill = ci_ribbon$fill, + ggplot2::aes_string(ymin = "ci_lower", ymax = "ci_upper", + fill = "legend_names[2]"), alpha = ci_ribbon$alpha - ) + ) + + scale_fill_manual( + name = "", values = c("CI 95%" = ci_ribbon$fill)) } - p <- p + ggplot2::geom_line( - ggplot2::aes_string(y = "y", color = "est$col"), - linetype = est$lty - ) + p <- p + + ggplot2::geom_line( + ggplot2::aes_string(y = "y", color = "legend_names[1]"), + # color = est$col, + linetype = est$lty + ) + + scale_colour_manual( + name = "", values = c("Estimate" = "blue")) - p <- p + ggplot2::labs(x = attrs$biomarker, y = attrs$estimate, color = "Legend") + p <- p + ggplot2::labs(x = attrs$biomarker, y = attrs$estimate) if (use_percentile) { p <- p + ggplot2::scale_x_continuous(labels = scales::percent) } diff --git a/man/g_step.Rd b/man/g_step.Rd index 6e648c8f6c..a5050d4982 100644 --- a/man/g_step.Rd +++ b/man/g_step.Rd @@ -8,7 +8,7 @@ g_step( df, use_percentile = "Percentile Center" \%in\% names(df), - est = list(col = "black", lty = 1), + est = list(col = "blue", lty = 1), ci_ribbon = list(fill = getOption("ggplot2.discrete.colour")[1], alpha = 0.5), col = getOption("ggplot2.discrete.colour") ) diff --git a/tern.Rproj b/tern.Rproj index 85d0bd5a18..0a45aaef37 100644 --- a/tern.Rproj +++ b/tern.Rproj @@ -17,5 +17,6 @@ StripTrailingWhitespace: Yes LineEndingConversion: Posix BuildType: Package +PackageUseDevtools: Yes PackageInstallArgs: --no-multiarch --with-keep.source PackageRoxygenize: rd,collate,namespace From f6ee611fda858b46a5718cb073ec62528755f0dd Mon Sep 17 00:00:00 2001 From: Melkiades Date: Tue, 8 Nov 2022 12:27:45 +0100 Subject: [PATCH 3/8] cleaning --- R/g_step.R | 1 - 1 file changed, 1 deletion(-) diff --git a/R/g_step.R b/R/g_step.R index 4d625243a0..141e3ffb74 100644 --- a/R/g_step.R +++ b/R/g_step.R @@ -115,7 +115,6 @@ g_step <- function(df, p <- p + ggplot2::geom_line( ggplot2::aes_string(y = "y", color = "legend_names[1]"), - # color = est$col, linetype = est$lty ) + scale_colour_manual( From f1ff5fd0f8aaa3427e2d30013f60d8ac11f42900 Mon Sep 17 00:00:00 2001 From: github-actions <41898282+github-actions[bot]@users.noreply.github.com> Date: Tue, 8 Nov 2022 11:31:06 +0000 Subject: [PATCH 4/8] [skip actions] Restyle files --- R/g_step.R | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/R/g_step.R b/R/g_step.R index 141e3ffb74..9885794368 100644 --- a/R/g_step.R +++ b/R/g_step.R @@ -105,12 +105,15 @@ g_step <- function(df, ci_ribbon$fill <- "lightblue" } p <- p + ggplot2::geom_ribbon( - ggplot2::aes_string(ymin = "ci_lower", ymax = "ci_upper", - fill = "legend_names[2]"), + ggplot2::aes_string( + ymin = "ci_lower", ymax = "ci_upper", + fill = "legend_names[2]" + ), alpha = ci_ribbon$alpha ) + scale_fill_manual( - name = "", values = c("CI 95%" = ci_ribbon$fill)) + name = "", values = c("CI 95%" = ci_ribbon$fill) + ) } p <- p + ggplot2::geom_line( @@ -118,7 +121,8 @@ g_step <- function(df, linetype = est$lty ) + scale_colour_manual( - name = "", values = c("Estimate" = "blue")) + name = "", values = c("Estimate" = "blue") + ) p <- p + ggplot2::labs(x = attrs$biomarker, y = attrs$estimate) if (use_percentile) { From e84516f166f1c528605e3abb240159b06a8ec6cf Mon Sep 17 00:00:00 2001 From: Melkiades Date: Tue, 8 Nov 2022 12:34:27 +0100 Subject: [PATCH 5/8] ghost comment --- R/g_step.R | 1 + 1 file changed, 1 insertion(+) diff --git a/R/g_step.R b/R/g_step.R index 9885794368..a6e23a5223 100644 --- a/R/g_step.R +++ b/R/g_step.R @@ -91,6 +91,7 @@ g_step <- function(df, attrs <- attributes(df) df$y <- df[[attrs$estimate]] + # Set legend names. To be modified also at call level legend_names <- c("Estimate", "CI 95%") p <- ggplot2::ggplot(df, ggplot2::aes_string(x = "x", y = "y")) From 631b4f35d55d92be33153121e236b5552e5b66cc Mon Sep 17 00:00:00 2001 From: Melkiades Date: Tue, 8 Nov 2022 17:12:10 +0100 Subject: [PATCH 6/8] if not silent what? --- tests/testthat/test-g_step.R | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/testthat/test-g_step.R b/tests/testthat/test-g_step.R index 833ddfa301..165292679d 100644 --- a/tests/testthat/test-g_step.R +++ b/tests/testthat/test-g_step.R @@ -14,7 +14,8 @@ step_matrix <- fit_survival_step( step_data <- broom::tidy(step_matrix) testthat::test_that("g_step works with default settings", { - testthat::expect_silent(g_step(step_data)) + testthat::expect_silent(gg <- g_step(step_data)) + testthat::expect_true(ggplot2::is.ggplot(gg)) }) testthat::test_that("g_step works with custom settings", { From 7032145be2d2e0955d18d1f7be0bfe36ddd2918a Mon Sep 17 00:00:00 2001 From: Melkiades Date: Tue, 8 Nov 2022 17:29:48 +0100 Subject: [PATCH 7/8] Still not sure about the output --- tests/testthat/test-g_step.R | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/tests/testthat/test-g_step.R b/tests/testthat/test-g_step.R index 165292679d..72e0e48407 100644 --- a/tests/testthat/test-g_step.R +++ b/tests/testthat/test-g_step.R @@ -14,17 +14,18 @@ step_matrix <- fit_survival_step( step_data <- broom::tidy(step_matrix) testthat::test_that("g_step works with default settings", { - testthat::expect_silent(gg <- g_step(step_data)) + gg <- g_step(step_data) testthat::expect_true(ggplot2::is.ggplot(gg)) }) testthat::test_that("g_step works with custom settings", { - testthat::expect_silent(g_step( + gg <- g_step( step_data, use_percentile = FALSE, est = list(col = "blue", lty = 1), ci_ribbon = NULL - )) + ) + testthat::expect_true(ggplot2::is.ggplot(gg)) }) testthat::test_that("tidy.step works as expected for survival STEP results", { From db942ef3d2df52560519075dcdf3d87bb9b2f20a Mon Sep 17 00:00:00 2001 From: Melkiades Date: Tue, 8 Nov 2022 17:52:54 +0100 Subject: [PATCH 8/8] news --- NEWS.md | 1 + 1 file changed, 1 insertion(+) diff --git a/NEWS.md b/NEWS.md index 81611c8f7b..dde09e3c22 100644 --- a/NEWS.md +++ b/NEWS.md @@ -5,6 +5,7 @@ * Updated all tests to use `rcd_2022_06_27` version of cached data. * Added more tests to increase code coverage. * Deprecated badge and warning for `wrap_txt` and its file. +* Added legend to `g_step`. ### Bug Fixes * Fixed bug causing incorrect ordering of numeric grade levels when missing grades are present in `s_count_occurrences_by_grade`.