Why is pval.size
ignored by ggsurvplot_facet()
?
I am trying to change the size of the p-value text in my survival plot using ggsurvplot_facet()
, but the call to pval.size
appears to be ignored. If anyone can help me change p-value size in my survival plot it would be very much appreciated.
Reproducible example:
library(survival); library(survminer)
fit <- survfit( Surv(time, status) ~ sex, data = colon)
ggsurvplot_facet(fit, colon, facet.by = "rx", palette = "jco", pval = TRUE, pval.size = 20)
ggsurvplot_facet(fit, colon, facet.by = "rx", palette = "jco", pval = TRUE, pval.size = 1)
The simple answer is that pval.size is not a named parameter in this function, and the function doesn't do anything with it when you pass it in.
You would have to change the body of the function to achieve a change in the size of the pval label. Here's how to create a modified function that takes the p value size parameter:
ggsurvplot_facet2 <- function(pval.size = 5, ...)
{
newcall <- bquote(
p <- p + geom_text(data = pvals.df, aes(x = pval.x, y = pval.y,
label = pval.txt), size = .(pval.size), hjust = 0)
)
body(ggsurvplot_facet)[[20]][[3]][[8]] <- newcall
ggsurvplot_facet(...)
}
So now you can do:
ggsurvplot_facet2(fit, colon, facet.by = "rx", palette = "jco", pval = TRUE, pval.size = 1)
Which gives this:
Then you can do
ggsurvplot_facet2(fit, colon, facet.by = "rx", palette = "jco", pval = TRUE, pval.size = 10)