Skip to content

Commit

Permalink
ggtext::element_markdown used to support vectorized inputs #455
Browse files Browse the repository at this point in the history
  • Loading branch information
kassambara committed Dec 9, 2020
1 parent acff36f commit 7c65df8
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 5 deletions.
8 changes: 5 additions & 3 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,15 @@ Imports:
tidyr,
survMisc,
purrr,
tibble,
rlang
tibble,
rlang,
ggtext (>= 0.1.0)
Suggests:
knitr,
flexsurv,
cmprsk,
markdown
markdown,
testthat
VignetteBuilder: knitr
URL: http://www.sthda.com/english/rpkgs/survminer/
BugReports: https://github.com/kassambara/survminer/issues
Expand Down
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

## Minor changes

- Since ggplot2 v3.3.0, the function `element_text()` issues a warning when vectorized arguments are provided, as in colour = c("red", "green", "blue"). This is a breaking change affecting the function `ggsurvtable()`. To fix this, the function `ggtext::element_markdown()` is now used in place of `element_text()` to handle vectorized colors (issue #455).

## Bug fixes


Expand Down
4 changes: 2 additions & 2 deletions R/ggsurvtable.R
Original file line number Diff line number Diff line change
Expand Up @@ -317,10 +317,10 @@ ggsurvtable <- function (fit, data = NULL, survtable = c("cumevents", "cumcenso
# Color table tick labels by strata
if(is.logical(y.text.col) & y.text.col[1] == TRUE){
cols <- .extract_ggplot_colors(p, grp.levels = legend.labs)
p <- p + theme(axis.text.y = element_text(colour = rev(cols)))
p <- p + theme(axis.text.y = ggtext::element_markdown(colour = rev(cols)))
}
else if(is.character(y.text.col))
p <- p + theme(axis.text.y = element_text(colour = rev(y.text.col)))
p <- p + theme(axis.text.y = ggtext::element_markdown(colour = rev(y.text.col)))

p

Expand Down
4 changes: 4 additions & 0 deletions tests/testthat.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
library(testthat)
library(survminer)

test_check("survminer")
16 changes: 16 additions & 0 deletions tests/testthat/test-ggsurvtable.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
context("test-ggsurvtable")

library(dplyr)
library("survival")
data("lung")
fit <- survfit(Surv(time, status) ~ sex, data = lung)

test_that("survtable y axis label colors work", {
p <- ggrisktable(fit, data = lung, color = "strata")
.build <- ggplot_build(p)
.build_data <- .build$data[[1]]
.table <- .build_data[, c("colour", "y")] %>%
dplyr::distinct()
expect_equal(.table$colour, c("#F8766D", "#00BFC4"))
expect_equal(as.numeric(.table$y), c(2, 1))
})

0 comments on commit 7c65df8

Please sign in to comment.