When I shift the x-axis of the ggplot using scale_x_continuous, the values in the first column of the risk table are partially covered.
library(tidyverse)
library(ggsurvfit)
p <-
survfit2(Surv(time, status) ~ sex, data = df_lung) %>%
ggsurvfit(linewidth = 1) +
scale_ggsurvfit() +
add_risktable(
risktable_stats = c("n.risk")) +
theme_classic()+
scale_x_continuous(expand=c(0, 1), limits = c(0, 34), breaks = seq(0, 30, 6))
p
How to move the x-axis without cropping part of the risk table?
Using base R, you could use the original
survival
package,aggregate
the survival table by strata from the fit and add it astext
. Theplot
will come with specificaxTicks(1)
whih we will use forsummary
and x-positions. Usingxpd=TRUE
allows usingtext
outside plotting region.