survminer
survminer copied to clipboard
Risk table alignment modifications - possible fix for #302 and #448
Improvements to alignment of risk table for various combinations of risk.table.pos, axes.offset, and whether or not xlim is specified.
Summary of changes:
- ggsurvplot_core()
- Added x-axis limits to the attr of the ggsurv object, which will be used by the .put_risktable_in_survplot function
- Added risk.table.pos to the pms object, which will be used by the .plot_survtable function
- .put_risktable_in_survplot()
- This function now has access to the x axis limits via the attr added in (1) above
- Where axes.offset=TRUE, xmin and xmax now allow for the default 5% axis expansion used in scale_x_continuous.
- Where axes.offset=FALSE, xmin and xmax are set without this 5% expansion
- Additionally where axes.offset=FALSE, minor improvement applied to the vertical position of the risk table values via change to ymin and ymax
- .plot_survtable()
- This function now has access to the risk.table.pos value
- Where axes.offset=FALSE, the "offset" from the origin is set to zero to align values with the y-axis.
- clip='off' prevents the first value on the risk table being cropped
- Where risk.table.pos="out" and axes.offset=FALSE, theme elements are updated to (i) make a margin between the strata labels and the first risk table value, and (ii) to remove elements that would obscure the risk table value such as the y-axis, y ticks, and border.
# Compare before and after
fit <- survfit(Surv(time, status) ~ sex, data = lung)
# Example 1
ggsurvplot(fit,
data = lung,
break.time.by = 100,
risk.table = TRUE,
risk.table.pos = "out",
axes.offset=F,
xlim=c(0,1020),
ggtheme = theme_classic())
# Example 2
ggsurvplot(fit,
data = lung,
break.time.by = 100,
risk.table = TRUE,
risk.table.pos = "in",
xlim=c(0,520),
ggtheme = theme_classic())
# Example 3
ggsurvplot(fit,
data = lung,
break.time.by = 100,
risk.table = TRUE,
risk.table.pos = "in",
axes.offset=F,
xlim=c(0,1020),
ggtheme = theme_classic())
Results example 1:
Results example 2:
Results example 3: