Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Risk table alignment modifications - possible fix for #302 and #448 #645

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

nolankm
Copy link

@nolankm nolankm commented Mar 9, 2024

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:

  1. 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
  1. .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
  1. .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:
image

Results example 2:
image

Results example 3:
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant