Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

License

Unknown, MIT licenses found

Licenses found

Unknown
LICENSE
MIT
LICENSE.md
NotificationsYou must be signed in to change notification settings

pharmaverse/ggsurvfit

Repository files navigation

R-CMD-checkCodecov test coverageCRAN status

Introduction

Theggsurvfit package eases the creation of time-to-event (akasurvival) summary figures with ggplot2. The concise and modular codecreates images that are ready for publication or sharing. Competingrisks cumulative incidence is also supported viaggcuminc().

Why ggsurvfit?

  • Use ggplot2 functions: Eachggsurvfit add-on function(e.g. add_confidence_interval(),add_risktable(), etc.) is writtenas a proper ggplot2‘geom’, meaningthe package functions can be woven with ggplot2 functions seamlessly.You don’t need to learn how to style the plot within the ggsurvfitfunctions: rather, rely on the suite of ggplot2 functions you alreadyknow.

  • Publishable Legends: Raw variable names do not appear in thefigure legend, e.g. "sex=Female".

  • Limitless Customization: You can modify the x-axis scales or anyother plot feature and the risk table will still align with the plot.

  • Simple Saving: Save individual images easily withggplot2::ggsave().

Installation

Installggsurvfit from CRAN with:

install.packages("ggsurvfit")

You can install the development version fromGitHub with:

# install.packages("devtools")devtools::install_github("pharmaverse/ggsurvfit")

Examples

Review thefiguregalleryfor many more examples.

The code below constructs a basic {ggsurvfit} figure withoutcustomization.

library(ggsurvfit)#> Loading required package: ggplot2p<- survfit2(Surv(time,status)~surg,data=df_colon)|>  ggsurvfit(linewidth=1)+  add_confidence_interval()+  add_risktable()+  add_quantile(y_value=0.6,color="gray50",linewidth=0.75)+  scale_ggsurvfit()

Any figure created with {ggsurvfit} can be customized using {ggplot2}functions.

p+# limit plot to show 8 years and less  coord_cartesian(xlim= c(0,8))+# update figure labels/titles  labs(y="Percentage Survival",title="Recurrence by Time From Surgery to Randomization",  )

survfit2() vssurvfit()

Both functions have identical inputs, so why do we needsurvfit2()?Thesurvfit2() tracks the environment from which the function wascalled, resulting in the following benefits.

  • We can reliably remove the raw variable names from the figure legend,e.g. SEX=Female.
  • P-values can be calculated withsurvfit_p() and added to figures.
  • The items above are oftenpossible usingsurvfit(). However, byutilizing the callingenvironment we areassured the correct elements are found, rather than crossing ourfingers that the search path contains the needed elements.

CDISC ADaM ADTTE

The package also includes gems for those using theCDISC ADaM ADTTEv1.0data model.

If columns"PARAM" or"PARAMCD" are present in the data frame passedtosurvfit2(), their values will be used to construct default labelsin theggsurvfit() figure.

The event indicator in ADTTE data sets is named"CNSR" and is coded inthe opposite way the survival package expects outcomes—1 = 'censored'and0 = 'event'. This difference creates an opportunity for errors tobe introduced in an analysis. Theggsurvfit package exports afunction calledSurv_CNSR() to resolve this concern. The functioncreates a survival object (e.g. survival::Surv()) that uses CDISC ADaMADTTE coding conventions as the default values. The function can be usedinggsurvfit as well as any other package that usessurvival::Surv().

survfit(Surv_CNSR()~1,adtte)#> Call: survfit(formula = Surv_CNSR() ~ 1, data = adtte)#>#>         n events median 0.95LCL 0.95UCL#> [1,] 2199    755    3.2     3.1    3.56

Related Packages

About

Resources

License

Unknown, MIT licenses found

Licenses found

Unknown
LICENSE
MIT
LICENSE.md

Contributing

Stars

Watchers

Forks

Contributors10

Languages


[8]ページ先頭

©2009-2025 Movatter.jp