- Notifications
You must be signed in to change notification settings - Fork24
License
Unknown, MIT licenses found
Licenses found
pharmaverse/ggsurvfit
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
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().
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 with
ggplot2::ggsave().
Installggsurvfit from CRAN with:
install.packages("ggsurvfit")You can install the development version fromGitHub with:
# install.packages("devtools")devtools::install_github("pharmaverse/ggsurvfit")
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", )
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 with
survfit_p()and added to figures. - The items above are oftenpossible using
survfit(). However, byutilizing the callingenvironment we areassured the correct elements are found, rather than crossing ourfingers that the search path contains the needed elements.
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
About
Resources
License
Unknown, MIT licenses found
Licenses found
Contributing
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Uh oh!
There was an error while loading.Please reload this page.
Contributors10
Uh oh!
There was an error while loading.Please reload this page.


