<?xml version="1.0" encoding="UTF-8" ?>
<!-- RSS generated by PHPBoost on Thu, 14 May 2026 02:29:29 +0200 -->

<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<title><![CDATA[Easy Guides]]></title>
		<atom:link href="https://www.sthda.com/english/syndication/rss/wiki/36" rel="self" type="application/rss+xml"/>
		<link>https://www.sthda.com</link>
		<description><![CDATA[Last articles of the category: survminer R package: Survival Data Analysis and Visualization]]></description>
		<copyright>(C) 2005-2026 PHPBoost</copyright>
		<language>en</language>
		<generator>PHPBoost</generator>
		
		
		<item>
			<title><![CDATA[Survminer Cheatsheet to Create Easily Survival Plots]]></title>
			<link>https://www.sthda.com/english/wiki/survminer-cheatsheet-to-create-easily-survival-plots</link>
			<guid>https://www.sthda.com/english/wiki/survminer-cheatsheet-to-create-easily-survival-plots</guid>
			<description><![CDATA[<!-- START HTML -->

            
  <!--====================== start from here when you copy to sthda================-->  
  <div id="rdoc">

<p><br/></p>
<p>We recently released the <a href="survminer-0-3-0">survminer verion 0.3</a>, which includes many new features to help in <a href="survival-analysis"><strong>visualizing</strong> and <strong>sumarizing</strong> <strong>survival analysis</strong></a> results.</p>
<p>In this article, we present a cheatsheet for survminer, created by <a href="https://github.com/pbiecek">Przemysław Biecek</a>, and provide an overview of main functions.</p>
<div id="survminer-cheatsheet" class="section level2">
<h2>survminer cheatsheet</h2>
<p>The cheatsheet can be downloaded from <a href = "https://www.sthda.com/english/rpkgs/survminer/survminer_cheatsheet.pdf", target = "_blank">STHDA</a> and from <a href="https://github.com/rstudio/cheatsheets/raw/master/source/pdfs/survminer_cheatsheet.pdf">Rstudio</a>. It contains selected important functions, such as:</p>
<ul>
<li><strong>ggsurvplot</strong>() for plotting survival curves</li>
<li><strong>ggcoxzph</strong>() and <strong>ggcoxdiagnostics</strong>() for assessing the assumtions of the Cox model</li>
<li><strong>ggforest</strong>() and <strong>ggcoxadjustedcurves</strong>() for summarizing a Cox model</li>
</ul>
<p>Additional functions, that you might find helpful, are briefly described in the next section.</p>
<p><a href = "https://www.sthda.com/english/rpkgs/survminer/survminer_cheatsheet.pdf"><img src = "/../sthda/RDoc/images/survminer-cheatsheet.jpeg"  alt = "survminer cheatsheet"/></a></p>
</div>
<div id="survminer-overview" class="section level2">
<h2>survminer overview</h2>
<p>The main functions, in the package, are organized in different categories as follow.</p>
<strong>Survival Curves</strong>
<hr/>
<ul>
<li><p><strong>ggsurvplot</strong>(): Draws survival curves with the ‘number at risk’ table, the cumulative number of events table and the cumulative number of censored subjects table.</p></li>
<li><p><strong>arrange_ggsurvplots</strong>(): Arranges multiple ggsurvplots on the same page.</p></li>
<li><p><strong>ggsurvevents</strong>(): Plots the distribution of event’s times.</p></li>
<li><p><strong>surv_summary</strong>(): Summary of a survival curve. Compared to the default summary() function, surv_summary() creates a data frame containing a nice summary from survfit results.</p></li>
<li><p><strong>surv_cutpoint</strong>(): Determines the optimal cutpoint for one or multiple continuous variables at once. Provides a value of a cutpoint that correspond to the most significant relation with survival.</p></li>
<li><p><strong>pairwise_survdiff</strong>(): Multiple comparisons of survival curves. Calculate pairwise comparisons between group levels with corrections for multiple testing.</p></li>
</ul>
<p><br/></p>
<strong>Diagnostics of Cox Model</strong>
<hr/>
<ul>
<li><p><strong>ggcoxzph</strong>(): Graphical test of proportional hazards. Displays a graph of the scaled Schoenfeld residuals, along with a smooth curve using ggplot2. Wrapper around plot.cox.zph().</p></li>
<li><p><strong>ggcoxdiagnostics</strong>(): Displays diagnostics graphs presenting goodness of Cox Proportional Hazards Model fit.</p></li>
<li><p><strong>ggcoxfunctional</strong>(): Displays graphs of continuous explanatory variable against martingale residuals of null cox proportional hazards model. It helps to properly choose the functional form of continuous variable in cox model.</p></li>
</ul>
<p><br/></p>
<strong>Summary of Cox Model</strong>
<hr/>
<ul>
<li><p><strong>ggforest</strong>(): Draws forest plot for CoxPH model.</p></li>
<li><p><strong>ggcoxadjustedcurves</strong>(): Plots adjusted survival curves for coxph model.</p></li>
</ul>
<p><br/></p>
<strong>Competing Risks</strong>
<hr/>
<ul>
<li><strong>ggcompetingrisks</strong>(): Plots cumulative incidence curves for competing risks.</li>
</ul>
<p><br/></p>
<p><span class="success">Find out more at <a href="https://www.sthda.com/english/rpkgs/survminer/" class="uri">https://www.sthda.com/english/rpkgs/survminer/</a>, and check out the documentation and usage examples of each of the functions in survminer package.</span></p>
</div>
<div id="infos" class="section level2">
<h2>Infos</h2>
<p><span class="warning"> This analysis has been performed using <strong>R software</strong> (ver. 3.3.2). </span></p>
</div>

<script>jQuery(document).ready(function () {
    jQuery('#rdoc h1').addClass('wiki_paragraph1');
    jQuery('#rdoc h2').addClass('wiki_paragraph2');
    jQuery('#rdoc h3').addClass('wiki_paragraph3');
    jQuery('#rdoc h4').addClass('wiki_paragraph4');
    });//add phpboost class to header</script>
<style>.content{padding:0px;}</style>
</div><!--end rdoc-->
<!--====================== stop here when you copy to sthda================-->


<!-- END HTML -->]]></description>
			<pubDate>Thu, 23 Mar 2017 16:46:13 +0100</pubDate>
			
		</item>
		
		<item>
			<title><![CDATA[survminer 0.3.0]]></title>
			<link>https://www.sthda.com/english/wiki/survminer-0-3-0</link>
			<guid>https://www.sthda.com/english/wiki/survminer-0-3-0</guid>
			<description><![CDATA[<!-- START HTML -->

  <!--====================== start from here when you copy to sthda================-->
  <div id="rdoc">

<p><br/></p>
<p>I’m very pleased to announce that <strong>survminer 0.3.0</strong> is now available on CRAN. survminer makes it easy to create elegant and informative <strong>survival curves</strong>. It includes also functions for summarizing and inspecting graphically the <a href="cox-model-assumptions"><strong>Cox proportional hazards model assumptions</strong></a>.</p>
<p>This is a big release and a special thanks goes to <a href="https://github.com/MarcinKosinski">Marcin Kosiński</a> and <a href="https://github.com/pbiecek">Przemysław Biecek</a> for their great works in actively improving and adding new features to the survminer package. The official online documentation is available at <a href="https://www.sthda.com/english/rpkgs/survminer/" class="uri">https://www.sthda.com/english/rpkgs/survminer/</a>.</p>

<br/>
<div id="TOC">
  <strong>Contents</strong><br/>
<ul>
<li><a href="#release-notes">Release notes</a></li>
<li><a href="#installing-and-loading-survminer">Installing and loading survminer</a></li>
<li><a href="#survival-curves">Survival curves</a></li>
<li><a href="#arranging-multiple-ggsurvplots-on-the-same-page">Arranging multiple ggsurvplots on the same page</a></li>
<li><a href="#distribution-of-events-times">Distribution of events’ times</a></li>
<li><a href="#adjusted-survival-curves-for-cox-model">Adjusted survival curves for Cox model</a></li>
<li><a href="#graphical-summary-of-cox-model">Graphical summary of Cox model</a></li>
<li><a href="#pairwise-comparisons-for-survival-curves">Pairwise comparisons for survival curves</a></li>
<li><a href="#visualizing-competing-risk-analysis">Visualizing competing risk analysis</a></li>
<li><a href="#related-articles">Related articles</a></li>
<li><a href="#infos">Infos</a></li>
</ul>
</div>

<div id="release-notes" class="section level2">
<h2>Release notes</h2>
<p>In this post, we present only the most important changes in v0.3.0. See the <a href="https://github.com/kassambara/survminer/blob/master/NEWS.md#survminer-030">release notes</a> for a complete list.</p>
<div id="new-arguments-in-ggsurvplot" class="section level3">
<h3>New arguments in ggsurvplot()</h3>
<ul>
<li><p><strong>data</strong>: Now, it’s recommended to specify the data used to compute survival curves (<a href="https://github.com/kassambara/survminer/issues/142">#142</a>). This will avoid the error generated when trying to use the <em>ggsurvplot()</em> function inside another functions (<a href="https://github.com/kassambara/survminer/issues/125">@zzawadz, #125</a>).</p></li>
<li><p><strong>cumevents</strong> and <strong>cumcensor</strong>: logical value for displaying the cumulative number of events table (<a href="https://github.com/kassambara/survminer/issues/117">#117</a>) and the cumulative number of censored subjects table (<a href="https://github.com/kassambara/survminer/issues/155">#155</a>), respectively.</p></li>
<li><p><strong>tables.theme</strong> for changing the theme of the tables under the main plot.</p></li>
<li><p><strong>pval.method</strong> and <strong>log.rank.weights</strong>: New possibilities to compare survival curves. Functionality based on <strong>survMisc::comp</strong> (<a href="https://github.com/kassambara/survminer/issues/17">@MarcinKosinski, #17</a>). Read also the following blog post on R-Addict website: <a href="http://r-addict.com/2017/02/09/Fancy-Survival-Plots.html">Comparing (Fancy) Survival Curves with Weighted Log-rank Tests</a>.</p></li>
</ul>
</div>
<div id="new-functions" class="section level3">
<h3>New functions</h3>
<ul>
<li><p><strong>pairwise_survdiff</strong>() for pairwise comparisons of survival curves (<a href="https://github.com/kassambara/survminer/issues/97">#97</a>).</p></li>
<li><p><strong>arrange_ggsurvplots</strong>() to arrange multiple ggsurvplots on the same page (<a href="https://github.com/kassambara/survminer/issues/66">#66</a>)</p></li>
</ul>
<p>Thanks to the work of <a href="https://github.com/pbiecek">Przemysław Biecek</a>, survminer 0.3.0 has received four new functions:</p>
<ul>
<li><p><strong>ggsurvevents</strong>() to plot the distribution of event’s times (<a href="https://github.com/kassambara/survminer/issues/116">@pbiecek, #116</a>).</p></li>
<li><p><strong>ggcoxadjustedcurves</strong>() to plot adjusted survival curves for Cox proportional hazards model (<a href="https://github.com/kassambara/survminer/issues/133">@pbiecek, #133</a> &amp; <a href="https://github.com/kassambara/survminer/issues/67">@markdanese, #67</a>).</p></li>
<li><p><strong>ggforest</strong>() to draw a forest plot (i.e. graphical summary) for the Cox model (<a href="https://github.com/kassambara/survminer/issues/114">@pbiecek, #114</a>).</p></li>
<li><p><strong>ggcompetingrisks</strong>() to plot the cumulative incidence curves for competing risks (<a href="https://github.com/kassambara/survminer/issues/168">@pbiecek, #168</a>).</p></li>
</ul>
</div>
<div id="vignettes-and-examples" class="section level3">
<h3>Vignettes and examples</h3>
<p>Two new vignettes were contributed by <a href="https://github.com/MarcinKosinski">Marcin Kosiński</a>:</p>
<ul>
<li><a href="https://www.sthda.com/english/rpkgs/survminer/articles/Playing_with_fonts_and_texts.html">Playing with fonts and texts (@MarcinKosinski)</a>.</li>
<li><a href="https://www.sthda.com/english/rpkgs/survminer/articles/Specifiying_weights_in_log-rank_comparisons.html">Specifiying weights in Log-rank comparisons (@MarcinKosinski)</a>.</li>
</ul>
</div>
</div>
<div id="installing-and-loading-survminer" class="section level2">
<h2>Installing and loading survminer</h2>
<p>Install the latest developmental version from <a href="https://github.com/kassambara/survminer">GitHub</a>:</p>
<pre class="r"><code>if(!require(devtools)) install.packages("devtools")
devtools::install_github("kassambara/survminer", build_vignettes = TRUE)</code></pre>
<p>Or, install the latest release from <a href="https://cran.r-project.org/package=survminer">CRAN</a> as follow:</p>
<pre class="r"><code>install.packages("survminer")</code></pre>
<p>To load survminer in R, type this:</p>
<pre class="r"><code>library("survminer")</code></pre>
</div>
<div id="survival-curves" class="section level2">
<h2>Survival curves</h2>
<p>New arguments displaying supplementary survival tables - <em>cumulative events &amp; censored subjects</em> - under the main survival curves:</p>
<br/>
<div class="block">
<ul>
<li><strong>risk.table = TRUE</strong>: Displays the risk table</li>
<li><strong>cumevents = TRUE</strong>: Displays the cumulative number of events table.</li>
<li><strong>cumcensor = TRUE</strong>: Displays the cumulative number of censoring table.</li>
<li><strong>tables.height = 0.25</strong>: Numeric value (in [0 - 1]) to adjust the height of all tables under the main survival plot.</li>
</ul>
</div>
<p><br/></p>
<pre class="r"><code># Fit survival curves
require("survival")
fit <- survfit(Surv(time, status) ~ sex, data = lung)

# Plot informative survival curves
library("survminer")
ggsurvplot(fit, data = lung,
           title = "Survival Curves",
           pval = TRUE, pval.method = TRUE,    # Add p-value &amp;  method name
           surv.median.line = "hv",            # Add median survival lines
           legend.title = "Sex",               # Change legend titles
           legend.labs = c("Male", "female"),  # Change legend labels
           palette = "jco",                    # Use JCO journal color palette
           risk.table = TRUE,                  # Add No at risk table
           cumevents = TRUE,                   # Add cumulative No of events table
           tables.height = 0.15,               # Specify tables height
           tables.theme = theme_cleantable(),  # Clean theme for tables
           tables.y.text = FALSE               # Hide tables y axis text
)</code></pre>
<div class="figure">
<img src="https://www.sthda.com/english/sthda/RDoc/figure/r-packages/survminer/survminer-0-3-0-survival-curves-1.png" alt="survminer" width="576" />
<p class="caption">
survminer
</p>
</div>
<p><span class="success">Cumulative events and censored tables are good additional feedback to survival curves, so that one could realize: what is the number of risk set AND what is the cause that the risk set become smaller: is it caused by events or by censored events?</span></p>
</div>
<div id="arranging-multiple-ggsurvplots-on-the-same-page" class="section level2">
<h2>Arranging multiple ggsurvplots on the same page</h2>
<p>The function <strong>arrange_ggsurvplots</strong>() [in <em>survminer</em>] can be used to arrange multiple ggsurvplots on the same page.</p>
<pre class="r"><code># List of ggsurvplots
splots <- list()
splots[[1]] <- ggsurvplot(fit, data = lung,
                          risk.table = TRUE,
                          tables.y.text = FALSE,
                          ggtheme = theme_light())

splots[[2]] <- ggsurvplot(fit, data = lung,
                          risk.table = TRUE,
                          tables.y.text = FALSE,
                          ggtheme = theme_grey())

# Arrange multiple ggsurvplots and print the output
arrange_ggsurvplots(splots, print = TRUE,
  ncol = 2, nrow = 1, risk.table.height = 0.25)</code></pre>
<div class="figure">
<img src="https://www.sthda.com/english/sthda/RDoc/figure/r-packages/survminer/survminer-0-3-0-arrange-multiple-ggsurvplot-1.png" alt="survminer" width="672" />
<p class="caption">
survminer
</p>
</div>
<p><br/></p>
<p>If you want to save the output into a pdf, type this:</p>
<pre class="r"><code># Arrange and save into pdf file
res <- arrange_ggsurvplots(splots, print = FALSE)
ggsave("myfile.pdf", res)</code></pre>
</div>
<div id="distribution-of-events-times" class="section level2">
<h2>Distribution of events’ times</h2>
<p>The function <strong>ggsurvevents</strong>() [in <em>survminer</em>] calculates and plots the distribution for events (both status = 0 and status = 1). It helps to notice when censoring is more common (<a href="https://github.com/kassambara/survminer/issues/116">@pbiecek, #116</a>). This is an alternative to cumulative events and censored tables, described in the previous section.</p>
<p>For example in colon dataset, as illustrated below, censoring occur mostly after the 6’th year:</p>
<pre class="r"><code>require("survival")
surv <- Surv(colon$time, colon$status)
ggsurvevents(surv)</code></pre>
<div class="figure">
<img src="https://www.sthda.com/english/sthda/RDoc/figure/r-packages/survminer/survminer-0-3-0-distribution-events-times-1.png" alt="survminer" width="576" />
<p class="caption">
survminer
</p>
</div>
</div>
<div id="adjusted-survival-curves-for-cox-model" class="section level2">
<h2>Adjusted survival curves for Cox model</h2>
<p>Adjusted survival curves show how a selected factor influences survival estimated from a cox model. If you want read more about why we need to adjust survival curves, see this document: <a href="https://cran.r-project.org/web/packages/survival/vignettes/adjcurve.pdf">Adjusted survival curves</a>.</p>
<p>Briefly, in clinical investigations, there are many situations, where several known factors, potentially affect patient prognosis. For example, suppose two groups of patients are compared: those with and those without a specific genotype. If one of the groups also contains older individuals, any difference in survival may be attributable to genotype or age or indeed both. Hence, when investigating survival in relation to any one factor, it is often desirable to adjust for the impact of others.</p>
<p>The cox proportional-hazards model is one of the most important methods used for modelling survival analysis data.</p>
<p>Here, we present the function <strong>ggcoxadjustedcurves</strong>() [in <em>survminer</em>] for plotting adjusted survival curves for cox proportional hazards model. The <strong>ggcoxadjustedcurves</strong>() function models the risks due to the confounders as described in the section 5.2 of this article: <a href="https://cran.r-project.org/web/packages/survival/vignettes/adjcurve.pdf">Terry M Therneau (2015); Adjusted survival curves</a>. Briefly, the key idea is to predict survival for all individuals in the cohort, and then take the average of the predicted curves by groups of interest (for example, sex, age, genotype groups, etc.).</p>
<pre class="r"><code># Data preparation and computing cox model
library(survival)
lung$sex <- factor(lung$sex, levels = c(1,2),
                   labels = c("Male", "Female"))
res.cox <- coxph(Surv(time, status) ~ sex + age + ph.ecog, data =  lung)

# Plot the baseline survival function
# with showing all individual predicted surv. curves
ggcoxadjustedcurves(res.cox, data = lung,
                    individual.curves = TRUE)</code></pre>
<div class="figure">
<img src="https://www.sthda.com/english/sthda/RDoc/figure/r-packages/survminer/survminer-0-3-0-adjusted-survival-curves-1.png" alt="survminer" width="576" />
<p class="caption">
survminer
</p>
</div>
<pre class="r"><code># Adjusted survival curves for the variable "sex"
ggcoxadjustedcurves(res.cox, data = lung,
                   variable  = lung[, "sex"],   # Variable of interest
                   legend.title = "Sex",        # Change legend title
                   palette = "npg",             # nature publishing group color palettes
                   curv.size = 2                # Change line size
                   )</code></pre>
<div class="figure">
<img src="https://www.sthda.com/english/sthda/RDoc/figure/r-packages/survminer/survminer-0-3-0-adjusted-survival-curves-2.png" alt="survminer" width="576" />
<p class="caption">
survminer
</p>
</div>
</div>
<div id="graphical-summary-of-cox-model" class="section level2">
<h2>Graphical summary of Cox model</h2>
<p>The function <strong>ggforest</strong>() [in <em>survminer</em>] can be used to create a graphical summary of a Cox model, also known as forest plot. For each covariate, it displays the hazard ratio (HR) and the 95% confidence intervals of the HR. By default, covariates with significant p-value are highlighted in red.</p>
<pre class="r"><code># Fit a Cox model
library(survival)
res.cox <- coxph(Surv(time, status) ~ sex + age + ph.ecog, data =  lung)
res.cox</code></pre>
<pre><code>## Call:
## coxph(formula = Surv(time, status) ~ sex + age + ph.ecog, data = lung)
##
##               coef exp(coef) se(coef)     z       p
## sexFemale -0.55261   0.57544  0.16774 -3.29 0.00099
## age        0.01107   1.01113  0.00927  1.19 0.23242
## ph.ecog    0.46373   1.58999  0.11358  4.08 4.4e-05
##
## Likelihood ratio test=30.5  on 3 df, p=1.08e-06
## n= 227, number of events= 164
##    (1 observation deleted due to missingness)</code></pre>
<pre class="r"><code># Create a forest plot
ggforest(res.cox)</code></pre>
<div class="figure">
<img src="https://www.sthda.com/english/sthda/RDoc/figure/r-packages/survminer/survminer-0-3-0-cox-model-forest-plot-1.png" alt="survminer" width="576" />
<p class="caption">
survminer
</p>
</div>
</div>
<div id="pairwise-comparisons-for-survival-curves" class="section level2">
<h2>Pairwise comparisons for survival curves</h2>
<p>When you compare three or more survival curves at once, the function <strong>survdiff</strong>() [in <em>survival</em> package] returns a global p-value whether to reject or not the null hypothesis.</p>
<p>With this, you know that a difference exists between groups, but you don’t know where. You can’t know until you test each combination.</p>
<p>Therefore, we implemented the function <strong>pairwise_survdiff</strong>() [in <em>survminer</em>]. It calculates pairwise comparisons between group levels with corrections for multiple testing.</p>
<ul>
<li><strong>Multiple survival curves with global p-value: </strong></li>
</ul>
<pre class="r"><code>library("survival")
library("survminer")
# Survival curves with global p-value
data(myeloma)
fit2 <- survfit(Surv(time, event) ~ molecular_group, data = myeloma)
ggsurvplot(fit2, data = myeloma,
           legend.title = "Molecular Group",
           legend.labs = levels(myeloma$molecular_group),
           legend = "right",
           pval = TRUE, palette = "lancet")</code></pre>
<div class="figure">
<img src="https://www.sthda.com/english/sthda/RDoc/figure/r-packages/survminer/survminer-0-3-0-pairwise-comparison-survival-curves-1.png" alt="survminer" width="672" />
<p class="caption">
survminer
</p>
</div>
<p><br/></p>
<ul>
<li><strong>Pairwise survdiff: </strong></li>
</ul>
<pre class="r"><code># Pairwise survdiff
res <- pairwise_survdiff(Surv(time, event) ~ molecular_group,
     data = myeloma)
res</code></pre>
<pre><code>##
##  Pairwise comparisons using Log-Rank test
##
## data:  myeloma and molecular_group
##
##                  Cyclin D-1 Cyclin D-2 Hyperdiploid Low bone disease MAF   MMSET
## Cyclin D-2       0.723      -          -            -                -     -
## Hyperdiploid     0.328      0.103      -            -                -     -
## Low bone disease 0.644      0.447      0.723        -                -     -
## MAF              0.943      0.723      0.103        0.523            -     -
## MMSET            0.103      0.038      0.527        0.485            0.038 -
## Proliferation    0.723      0.988      0.103        0.485            0.644 0.062
##
## P value adjustment method: BH</code></pre>
<ul>
<li><strong>Symbolic number coding: </strong></li>
</ul>
<pre class="r"><code># Symbolic number coding
symnum(res$p.value, cutpoints = c(0, 0.0001, 0.001, 0.01, 0.05, 0.1, 1),
   symbols = c("****", "***", "**", "*", "+", " "),
   abbr.colnames = FALSE, na = "")</code></pre>
<pre><code>##                  Cyclin D-1 Cyclin D-2 Hyperdiploid Low bone disease MAF MMSET
## Cyclin D-2
## Hyperdiploid
## Low bone disease
## MAF
## MMSET                       *                                        *
## Proliferation                                                            +
## attr(,"legend")
## [1] 0 &amp;#39;****&amp;#39; 1e-04 &amp;#39;***&amp;#39; 0.001 &amp;#39;**&amp;#39; 0.01 &amp;#39;*&amp;#39; 0.05 &amp;#39;+&amp;#39; 0.1 &amp;#39; &amp;#39; 1 \t    ## NA: &amp;#39;&amp;#39;</code></pre>
</div>
<div id="visualizing-competing-risk-analysis" class="section level2">
<h2>Visualizing competing risk analysis</h2>
<p>Competing risk events refer to a situation where an individual (patient) is at risk of more than one mutually exclusive event, such as death from different causes, and the occurrence of one of these will prevent any other event from ever happening.</p>
<p>For example, when studying relapse in patients who underwent HSCT (Hematopoietic stem cell transplantation), transplant related mortality is a competing risk event and the cumulative incidence function (CIF) must be calculated by appropriate accounting.</p>
<p>A ‘competing risks’ analysis is implemented in the R package <a href="https://CRAN.R-project.org/package=cmprsk">cmprsk</a>. Here, we provide the <strong>ggcompetingrisks</strong>() function [in <em>survminer</em>] to plot the results using ggplot2-based elegant data visualization.</p>
<pre class="r"><code># Create a demo data set
#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
set.seed(2)
failure_time <- rexp(100)
status <- factor(sample(0:2, 100, replace=TRUE), 0:2,
                 c(&amp;#39;no event&amp;#39;, &amp;#39;death&amp;#39;, &amp;#39;progression&amp;#39;))
disease <- factor(sample(1:3,  100,replace=TRUE), 1:3,
                  c(&amp;#39;BRCA&amp;#39;,&amp;#39;LUNG&amp;#39;,&amp;#39;OV&amp;#39;))

# Cumulative Incidence Function
#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
require(cmprsk)
fit3 <- cuminc(ftime = failure_time, fstatus = status,
              group = disease)

# Visualize
#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
ggcompetingrisks(fit3, palette = "Dark2",
                 legend = "top",
                 ggtheme = theme_bw())</code></pre>
<div class="figure">
<img src="https://www.sthda.com/english/sthda/RDoc/figure/r-packages/survminer/survminer-0-3-0-competing-risk-1.png" alt="survminer" width="672" />
<p class="caption">
survminer
</p>
</div>
<p>The <strong>ggcometingrisks</strong>() function has also support for <strong>multi-state survival</strong> objects (type = “mstate”), where the status variable can have multiple levels. The first of these will stand for censoring, and the others for various event types, e.g., causes of death.</p>
<pre class="r"><code># Data preparation
df <- data.frame(time = failure_time, status = status,
                 group = disease)

# Fit multi-state survival
library(survival)
fit5 <- survfit(Surv(time, status, type = "mstate") ~ group, data = df)
ggcompetingrisks(fit5, palette = "jco")</code></pre>
<div class="figure">
<img src="https://www.sthda.com/english/sthda/RDoc/figure/r-packages/survminer/survminer-0-3-0-multi-state-survival-1.png" alt="survminer" width="672" />
<p class="caption">
survminer
</p>
</div>
</div>
<div id="related-articles" class="section level2">
<h2>Related articles</h2>
<ul>
<li><a href="survival-analysis">Survival Analysis</a>
<ul>
<li><a href="survival-analysis-basics">Survival Analysis Basics: Curves and Logrank Tests</a></li>
<li><a href="cox-proportional-hazards-model">Cox Proportional Hazards Model</a></li>
<li><a href="cox-model-assumptions">Cox Model Assumptions</a></li>
</ul></li>
</ul>
</div>
<div id="infos" class="section level2">
<h2>Infos</h2>
<p><span class="warning"> This analysis has been performed using <strong>R software</strong> (ver. 3.3.2). </span></p>
</div>

<script>jQuery(document).ready(function () {
    jQuery('#rdoc h1').addClass('wiki_paragraph1');
    jQuery('#rdoc h2').addClass('wiki_paragraph2');
    jQuery('#rdoc h3').addClass('wiki_paragraph3');
    jQuery('#rdoc h4').addClass('wiki_paragraph4');
    });//add phpboost class to header</script>
<style>.content{padding:0px;}</style>
</div><!--end rdoc-->
<!--====================== stop here when you copy to sthda================-->

<!-- END HTML -->]]></description>
			<pubDate>Mon, 20 Mar 2017 16:45:51 +0100</pubDate>
			
		</item>
		
		<item>
			<title><![CDATA[survminer 0.2.4]]></title>
			<link>https://www.sthda.com/english/wiki/survminer-0-2-4</link>
			<guid>https://www.sthda.com/english/wiki/survminer-0-2-4</guid>
			<description><![CDATA[<!-- START HTML -->

  <!--====================== start from here when you copy to sthda================-->  
  <div id="rdoc">




<p><br/></p>
<p>I’m very pleased to announce survminer 0.2.4. It comes with many new features and minor changes.</p>
<p>Install survminer with:</p>
<pre class="r"><code>install.packages("survminer")</code></pre>
<p>To load the package, type this:</p>
<pre class="r"><code>library(survminer)</code></pre>

<br/>
<div id="TOC" class = "block">
  <strong>Contents</strong><br/>
<ul>
<li><a href="#new-features">New features</a></li>
<li><a href="#minor-changes">Minor changes</a></li>
<li><a href="#bug-fixes">Bug fixes</a></li>
<li><a href="#summary-of-survival-curves">Summary of survival curves</a></li>
<li><a href="#plot-survival-curves">Plot survival curves</a></li>
<li><a href="#determine-the-optimal-cutpoint-for-continuous-variables">Determine the optimal cutpoint for continuous variables</a></li>
<li><a href="#facet-the-output-of-ggsurvplot">Facet the output of ggsurvplot()</a></li>
<li><a href="#related-articles">Related articles</a></li>
<li><a href="#infos">Infos</a></li>
</ul>
</div>
<br/>

<div id="new-features" class="section level2">
<h2>New features</h2>
<ul>
<li>New function <code>surv_summary()</code> for creating data frame containing a nice summary of survival curves (<a href="https://github.com/kassambara/survminer/issues/64">#64</a>).</li>
<li>It’s possible now to facet the output of <code>ggsurvplot()</code> by one or more factors (<a href="https://github.com/kassambara/survminer/issues/64">#64</a>).</li>
<li>Now, <code>ggsurvplot()</code> can be used to plot cox model (<a href="https://github.com/kassambara/survminer/issues/67">#67</a>).</li>
<li>New functions added for determining and visualizing the optimal cutpoint of continuous variables for survival analyses:
<ul>
<li><code>surv_cutpoint()</code>: Determine the optimal cutpoint for each variable using ‘maxstat’. Methods defined for surv_cutpoint object are summary(), print() and plot().</li>
<li><code>surv_categorize()</code>: Divide each variable values based on the cutpoint returned by <code>surv_cutpoint()</code> (<a href="https://github.com/kassambara/survminer/issues/41">#41</a>).</li>
</ul></li>
<li>New argument ‘ncensor.plot’ added to <code>ggsurvplot()</code>. A logical value. If TRUE, the number of censored subjects at time t is plotted. Default is FALSE (<a href="https://github.com/kassambara/survminer/issues/18">#18</a>).</li>
</ul>
</div>
<div id="minor-changes" class="section level2">
<h2>Minor changes</h2>
<ul>
<li>New argument ‘conf.int.style’ added in <code>ggsurvplot()</code> for changing the style of confidence interval bands.</li>
<li>Now, <code>ggsurvplot()</code> plots a stepped confidence interval when conf.int = TRUE (<a href="https://github.com/kassambara/survminer/issues/65">#65</a>).</li>
<li><code>ggsurvplot()</code> updated for compatibility with the future version of ggplot2 (v2.2.0) (<a href="https://github.com/kassambara/survminer/issues/68">#68</a>)</li>
<li>ylab is now automatically adapted according to the value of the argument <code>fun</code>. For example, if fun = “event”, then ylab will be “Cumulative event”.</li>
<li>In <code>ggsurvplot()</code>, linetypes can now be adjusted by variables used to fit survival curves (<a href="https://github.com/kassambara/survminer/issues/46">#46</a>)</li>
<li>In <code>ggsurvplot()</code>, the argument risk.table can be either a logical value (TRUE|FALSE) or a string (“absolute”, “percentage”). If risk.table = “absolute”, <code>ggsurvplot()</code> displays the absolute number of subjects at risk. If risk.table = “percentage”, the percentage at risk is displayed. Use “abs_pct” to show both the absolute number and the percentage of subjects at risk. (<a href="https://github.com/kassambara/survminer/issues/70">#70</a>).</li>
<li>New argument surv.median.line in <code>ggsurvplot()</code>: character vector for drawing a horizontal/vertical line at median (50%) survival. Allowed values include one of c(“none”, “hv”, “h”, “v”). v: vertical, h:horizontal (<a href="https://github.com/kassambara/survminer/issues/61">#61</a>).</li>
<li>Now, the default theme of ggcoxdiagnostics() is ggplot2::theme_bw().</li>
</ul>
</div>
<div id="bug-fixes" class="section level2">
<h2>Bug fixes</h2>
<p>It also includes numerous bug fixes as described in the release notes: <a href="https://github.com/kassambara/survminer/releases/tag/v0.2.3">v0.2.3</a> and <a href="https://github.com/kassambara/survminer/releases/tag/v0.2.4">v0.2.4</a></p>
</div>
<div id="summary-of-survival-curves" class="section level2">
<h2>Summary of survival curves</h2>
<p>Compared to the default summary() function, the surv_summary() function [in survminer] creates a data frame containing a nice summary from survfit results.</p>
<pre class="r"><code># Fit survival curves
require("survival")
fit <- survfit(Surv(time, status) ~ sex, data = lung)

# Summarize
library("survminer")
res.sum <- surv_summary(fit)
head(res.sum)</code></pre>
<pre><code>##   time n.risk n.event n.censor      surv    std.err     upper     lower
## 1   11    138       3        0 0.9782609 0.01268978 1.0000000 0.9542301
## 2   12    135       1        0 0.9710145 0.01470747 0.9994124 0.9434235
## 3   13    134       2        0 0.9565217 0.01814885 0.9911586 0.9230952
## 4   15    132       1        0 0.9492754 0.01967768 0.9866017 0.9133612
## 5   26    131       1        0 0.9420290 0.02111708 0.9818365 0.9038355
## 6   30    130       1        0 0.9347826 0.02248469 0.9768989 0.8944820
##   strata sex
## 1  sex=1   1
## 2  sex=1   1
## 3  sex=1   1
## 4  sex=1   1
## 5  sex=1   1
## 6  sex=1   1</code></pre>
<pre class="r"><code># Information about the survival curves
attr(res.sum, "table")</code></pre>
<pre><code>##       records n.max n.start events   *rmean *se(rmean) median 0.95LCL
## sex=1     138   138     138    112 325.0663   22.59845    270     212
## sex=2      90    90      90     53 458.2757   33.78530    426     348
##       0.95UCL
## sex=1     310
## sex=2     550</code></pre>
</div>
<div id="plot-survival-curves" class="section level2">
<h2>Plot survival curves</h2>
<pre class="r"><code>ggsurvplot(
   fit,                     # survfit object with calculated statistics.
   pval = TRUE,             # show p-value of log-rank test.
   conf.int = TRUE,         # show confidence intervals for 
                            # point estimaes of survival curves.
   #conf.int.style = "step",  # customize style of confidence intervals
   xlab = "Time in days",   # customize X axis label.
   break.time.by = 200,     # break X axis in time intervals by 200.
   ggtheme = theme_light(), # customize plot and risk table with a theme.
   risk.table = "abs_pct",  # absolute number and percentage at risk.
  risk.table.y.text.col = T,# colour risk table text annotations.
  risk.table.y.text = FALSE,# show bars instead of names in text annotations
                            # in legend of risk table.
  ncensor.plot = TRUE,      # plot the number of censored subjects at time t
  surv.median.line = "hv",  # add the median survival pointer.
  legend.labs = 
    c("Male", "Female"),    # change legend labels.
  palette = 
    c("#E7B800", "#2E9FDF") # custom color palettes.
)</code></pre>
<div class="figure">
<img src="https://www.sthda.com/english/sthda/RDoc/figure/r-packages/survminer/survminer-0-2-4-customized-survival-plot-1.png" alt="survminer" width="672" />
<p class="caption">
survminer
</p>
</div>
</div>
<div id="determine-the-optimal-cutpoint-for-continuous-variables" class="section level2">
<h2>Determine the optimal cutpoint for continuous variables</h2>
<p>The survminer package determines the optimal cutpoint for one or multiple continuous variables at once, using the maximally selected rank statistics from the ‘maxstat’ R package. To learn more, read this: M. Kosiński. R-ADDICT November 2016. <a href="http://r-addict.com/2016/11/21/Optimal-Cutpoint-maxstat.html">Determine optimal cutpoints for numerical variables in survival plots</a>.</p>
<p>Here, we’ll use the myeloma data sets [in the survminer package]. It contains survival data and some gene expression data obtained from multiple myeloma patients.</p>
<pre class="r"><code># 0. Load some data
data(myeloma)
head(myeloma[, 1:8])</code></pre>
<pre><code>##          molecular_group chr1q21_status treatment event  time   CCND1
## GSM50986      Cyclin D-1       3 copies       TT2     0 69.24  9908.4
## GSM50988      Cyclin D-2       2 copies       TT2     0 66.43 16698.8
## GSM50989           MMSET       2 copies       TT2     0 66.50   294.5
## GSM50990           MMSET       3 copies       TT2     1 42.67   241.9
## GSM50991             MAF           <NA>       TT2     0 65.00   472.6
## GSM50992    Hyperdiploid       2 copies       TT2     0 65.20   664.1
##          CRIM1 DEPDC1
## GSM50986 420.9  523.5
## GSM50988  52.0   21.1
## GSM50989 617.9  192.9
## GSM50990  11.9  184.7
## GSM50991  38.8  212.0
## GSM50992  16.9  341.6</code></pre>
<pre class="r"><code># 1. Determine the optimal cutpoint of variables
res.cut <- surv_cutpoint(myeloma, time = "time", event = "event",
   variables = c("DEPDC1", "WHSC1", "CRIM1"))

summary(res.cut)</code></pre>
<pre><code>##        cutpoint statistic
## DEPDC1    279.8  4.275452
## WHSC1    3205.6  3.361330
## CRIM1      82.3  1.968317</code></pre>
<pre class="r"><code># 2. Plot cutpoint for DEPDC1
# palette = "npg" (nature publishing group), see ?ggpubr::ggpar
plot(res.cut, "DEPDC1", palette = "npg")</code></pre>
<pre><code>## $DEPDC1</code></pre>
<div class="figure">
<img src="https://www.sthda.com/english/sthda/RDoc/figure/r-packages/survminer/survminer-0-2-4-maxstat-cutpoint-1.png" alt="survminer" width="624" />
<p class="caption">
survminer
</p>
</div>
<pre class="r"><code># 3. Categorize variables
res.cat <- surv_categorize(res.cut)
head(res.cat)</code></pre>
<pre><code>##           time event DEPDC1 WHSC1 CRIM1
## GSM50986 69.24     0   high   low  high
## GSM50988 66.43     0    low   low   low
## GSM50989 66.50     0    low  high  high
## GSM50990 42.67     1    low  high   low
## GSM50991 65.00     0    low   low   low
## GSM50992 65.20     0   high   low   low</code></pre>
<pre class="r"><code># 4. Fit survival curves and visualize
library("survival")
fit <- survfit(Surv(time, event) ~DEPDC1, data = res.cat)
ggsurvplot(fit, risk.table = TRUE, conf.int = TRUE)</code></pre>
<div class="figure">
<img src="https://www.sthda.com/english/sthda/RDoc/figure/r-packages/survminer/survminer-0-2-4-maxstat-cutpoint-2.png" alt="survminer" width="624" />
<p class="caption">
survminer
</p>
</div>
</div>
<div id="facet-the-output-of-ggsurvplot" class="section level2">
<h2>Facet the output of ggsurvplot()</h2>
<p>In this section, we’ll compute survival curves using the combination of multiple factors. Next, we’ll factet the output of ggsurvplot() by a combination of factors</p>
<ol style="list-style-type: decimal">
<li>Fit (complex) survival curves using colon data sets</li>
</ol>
<pre class="r"><code>require("survival")
fit2 <- survfit( Surv(time, status) ~ sex + rx + adhere,
                data = colon )</code></pre>
<ol start="2" style="list-style-type: decimal">
<li>Visualize the output using survminer</li>
</ol>
<pre class="r"><code>ggsurv <- ggsurvplot(fit2, fun = "event", conf.int = TRUE,
  risk.table = TRUE, risk.table.col="strata", 
  ggtheme = theme_bw())

ggsurv</code></pre>
<div class="figure">
<img src="https://www.sthda.com/english/sthda/RDoc/figure/r-packages/survminer/survminer-0-2-4-complexe-survival-curves-1.png" alt="survminer" width="672" />
<p class="caption">
survminer
</p>
</div>
<ol start="3" style="list-style-type: decimal">
<li>Faceting survival curves. The plot below shows survival curves by the sex variable faceted according to the values of rx &amp; adhere.</li>
</ol>
<pre class="r"><code>curv_facet <- ggsurv$plot + facet_grid(rx ~ adhere)
curv_facet</code></pre>
<div class="figure">
<img src="https://www.sthda.com/english/sthda/RDoc/figure/r-packages/survminer/survminer-0-2-4-survival-curves-facet-1.png" alt="survminer" width="672" />
<p class="caption">
survminer
</p>
</div>
<ol start="4" style="list-style-type: decimal">
<li>Facetting risk tables: Generate risk table for each facet plot item</li>
</ol>
<pre class="r"><code>ggsurv$table + facet_grid(rx ~ adhere, scales = "free")+
 theme(legend.position = "none")</code></pre>
<div class="figure">
<img src="https://www.sthda.com/english/sthda/RDoc/figure/r-packages/survminer/survminer-0-2-4-risk-table-facet-1.png" alt="survminer" width="576" />
<p class="caption">
survminer
</p>
</div>
<ol start="5" style="list-style-type: decimal">
<li>Generate risk table for each facet columns</li>
</ol>
<pre class="r"><code>tbl_facet <- ggsurv$table + facet_grid(.~ adhere, scales = "free")
tbl_facet + theme(legend.position = "none")</code></pre>
<div class="figure">
<img src="https://www.sthda.com/english/sthda/RDoc/figure/r-packages/survminer/survminer-0-2-4-risk-table-facet2-1.png" alt="survminer" width="624" />
<p class="caption">
survminer
</p>
</div>
<pre class="r"><code># Arrange faceted survival curves and risk tables
g2 <- ggplotGrob(curv_facet)
g3 <- ggplotGrob(tbl_facet)
min_ncol <- min(ncol(g2), ncol(g3))
g <- gridExtra::rbind.gtable(g2[, 1:min_ncol], g3[, 1:min_ncol], size="last")
g$widths <- grid::unit.pmax(g2$widths, g3$widths)
grid::grid.newpage()
grid::grid.draw(g)</code></pre>
<div class="figure">
<img src="https://www.sthda.com/english/sthda/RDoc/figure/r-packages/survminer/survminer-0-2-4-risk-table-facet3-1.png" alt="survminer" width="624" />
<p class="caption">
survminer
</p>
</div>
</div>
<div id="related-articles" class="section level2">
<h2>Related articles</h2>
<ul>
<li><a href="https://www.sthda.com/english/english/wiki/survival-analysis-basics">Survival Analysis Basics: Curves and Logrank Tests</a></li>
<li><a href="https://www.sthda.com/english/english/wiki/cox-proportional-hazards-model">Cox Proportional Hazards Model</a></li>
<li><a href="https://www.sthda.com/english/english/wiki/cox-model-assumptions">Cox Model Assumptions</a></li>
</ul>
</div>
<div id="infos" class="section level2">
<h2>Infos</h2>
<p><span class="warning"> This analysis has been performed using <strong>R software</strong> (ver. 3.3.2). </span></p>
</div>

<script>jQuery(document).ready(function () {
    jQuery('#rdoc h1').addClass('wiki_paragraph1');
    jQuery('#rdoc h2').addClass('wiki_paragraph2');
    jQuery('#rdoc h3').addClass('wiki_paragraph3');
    jQuery('#rdoc h4').addClass('wiki_paragraph4');
    });//add phpboost class to header</script>
<style>.content{padding:0px;}</style>
</div><!--end rdoc-->
<!--====================== stop here when you copy to sthda================-->


<!-- END HTML -->]]></description>
			<pubDate>Tue, 13 Dec 2016 00:34:59 +0100</pubDate>
			
		</item>
		
		<item>
			<title><![CDATA[survminer R package: Survival Data Analysis and Visualization]]></title>
			<link>https://www.sthda.com/english/wiki/survminer-r-package-survival-data-analysis-and-visualization</link>
			<guid>https://www.sthda.com/english/wiki/survminer-r-package-survival-data-analysis-and-visualization</guid>
			<description><![CDATA[<!-- START HTML -->


  <!--====================== start from here when you copy to sthda================-->  
  <div id="rdoc">

<div id="TOC">
<ul>
<li><a href="#survminer---main-features">survminer - Main features</a></li>
<li><a href="#installation-and-loading">Installation and loading</a></li>
<li><a href="#getting-started">Getting started</a><ul>
<li><a href="#draw-survival-curves-without-grouping">Draw survival curves without grouping</a></li>
<li><a href="#draw-survival-curves-with-two-groups">Draw survival curves with two groups</a><ul>
<li><a href="#basic-plots">Basic plots</a></li>
<li><a href="#change-font-size-style-and-color">Change font size, style and color</a></li>
<li><a href="#change-legend-title-labels-and-position">Change legend title, labels and position</a></li>
<li><a href="#change-line-types-and-color-palettes">Change line types and color palettes</a></li>
<li><a href="#add-number-at-risk-table">Add number at risk table</a></li>
<li><a href="#change-x-axis-limits">Change x axis limits</a></li>
<li><a href="#transform-survival-curves-plot-cumulative-events-and-hazard-function">Transform survival curves: plot cumulative events and hazard function</a></li>
</ul></li>
<li><a href="#survival-curves-with-multiple-groups">Survival curves with multiple groups</a></li>
</ul></li>
<li><a href="#infos">Infos</a></li>
</ul>
</div>

<p><br/></p>
<p><strong>Survival analysis</strong> focuses on the expected duration of time until occurrence of an event of interest. However, this failure time may not be observed within the study time period, producing the so-called <strong>censored</strong> observations.</p>
<p>The R package <strong>survival</strong> fits and plots survival curves using R base graphs. There are also several R packages/functions for drawing <strong>survival curves</strong> using ggplot2 system:</p>
<ul>
<li><strong>ggsurv()</strong> function in <a href="https://www.sthda.com/english/wiki/(/wiki/ggplot2-quick-correlation-matrix-heatmap-r-software-and-data-visualization)"><strong>GGally</strong></a> R package</li>
<li><strong>autoplot()</strong> function <a href="https://www.sthda.com/english/english/wiki/ggfortify-extension-to-ggplot2-to-handle-some-popular-packages-r-software-and-data-visualization"><strong>ggfortify</strong></a> R package</li>
</ul>
<br/>
<div class="warning">
<p>These packages/functions are limited:</p>
<ul>
<li><p>The default graph generated with the R package <strong>survival</strong> is ugly and it requires programming skills for drawing a nice looking survival curves. There is no option for displaying the <strong>‘number at risk’</strong> table.</p></li>
<li><strong>GGally</strong> and <strong>ggfortify</strong> don’t contain any option for drawing the <strong>‘number at risk’</strong> table. You need also some knowledge in <strong>ggplot2</strong> plotting system for drawing a ready-to-publish survival curves.</li>
</ul>
</div>
<p><br/></p>
<p><span class="success"> Here, we developed and present the <strong>survminer</strong> R package for facilitating <strong>survival analysis</strong> and <strong>visualization</strong>. </span></p>
<div id="survminer---main-features" class="section level1">
<h1>survminer - Main features</h1>
<p>The current version contains the function <strong>ggsurvplot()</strong> for easily drawing beautiful and ready-to-publish survival curves using <strong>ggplot2</strong>. <strong>ggsurvplot()</strong> includes also some options for displaying the <strong>p-value</strong> and the <strong>‘number at risk’ table</strong>, under the survival curves.</p>
</div>
<div id="installation-and-loading" class="section level1">
<h1>Installation and loading</h1>
<p>Install from CRAN:</p>
<pre class="r"><code>install.packages("survminer")</code></pre>
<p>Or, install the latest version from GitHub:</p>
<pre class="r"><code># Install
if(!require(devtools)) install.packages("devtools")
devtools::install_github("kassambara/survminer")</code></pre>
<pre class="r"><code># Loading
library("survminer")</code></pre>
</div>
<div id="getting-started" class="section level1">
<h1>Getting started</h1>
<p><span class="notice">The R package <strong>survival</strong> is required for fitting survival curves.</span></p>
<div id="draw-survival-curves-without-grouping" class="section level2">
<h2>Draw survival curves without grouping</h2>
<pre class="r"><code># Fit survival curves
require("survival")
fit <- survfit(Surv(time, status) ~ 1, data = lung)

# Drawing curves
ggsurvplot(fit, color = "#2E9FDF")</code></pre>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/survminer/surminer-ggplot2-survival-plot-all-1.png" title="" alt="" width="518.4" /></p>
</div>
<div id="draw-survival-curves-with-two-groups" class="section level2">
<h2>Draw survival curves with two groups</h2>
<div id="basic-plots" class="section level3">
<h3>Basic plots</h3>
<pre class="r"><code># Fit survival curves
require("survival")
fit<- survfit(Surv(time, status) ~ sex, data = lung)

# Drawing survival curves
ggsurvplot(fit)</code></pre>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/survminer/surminer-ggplot2-survival-plot-two-groups-basics-1.png" title="" alt="" width="518.4" /></p>
</div>
<div id="change-font-size-style-and-color" class="section level3">
<h3>Change font size, style and color</h3>
<pre class="r"><code># Change font style, size and color
#++++++++++++++++++++++++++++++++++++
# Change only font size
ggsurvplot(fit, main = "Survival curve",
   font.main = 18,
   font.x =  16,
   font.y = 16,
   font.tickslab = 14)</code></pre>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/survminer/surminer-ggplot2-survival-plot-font-1.png" title="" alt="" width="518.4" /></p>
<pre class="r"><code># Change font size, style and color at the same time
ggsurvplot(fit, main = "Survival curve",
   font.main = c(16, "bold", "darkblue"),
   font.x = c(14, "bold.italic", "red"),
   font.y = c(14, "bold.italic", "darkred"),
   font.tickslab = c(12, "plain", "darkgreen"))</code></pre>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/survminer/surminer-ggplot2-survival-plot-font-2.png" title="" alt="" width="518.4" /></p>
</div>
<div id="change-legend-title-labels-and-position" class="section level3">
<h3>Change legend title, labels and position</h3>
<pre class="r"><code># Change the legend title and labels
ggsurvplot(fit, legend = "bottom", 
           legend.title = "Sex",
           legend.labs = c("Male", "Female"))</code></pre>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/survminer/surminer-ggplot2-survival-plot-two-groups-legends-1.png" title="" alt="" width="518.4" /></p>
<pre class="r"><code># Specify legend position by its coordinates
ggsurvplot(fit, legend = c(0.2, 0.2))</code></pre>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/survminer/surminer-ggplot2-survival-plot-two-groups-legends-2.png" title="" alt="" width="518.4" /></p>
</div>
<div id="change-line-types-and-color-palettes" class="section level3">
<h3>Change line types and color palettes</h3>
<pre class="r"><code># change line size --> 1
# Change line types by groups (i.e. "strata")
# and change color palette
ggsurvplot(fit,  size = 1,  # change line size
           linetype = "strata", # change line type by groups
           break.time.by = 250, # break time axis by 250
           palette = c("#E7B800", "#2E9FDF"), # custom color palette
           conf.int = TRUE, # Add confidence interval
           pval = TRUE # Add p-value
           )</code></pre>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/survminer/surminer-ggplot2-survival-plot-line-types-colors-1.png" title="" alt="" width="518.4" /></p>
<pre class="r"><code># Use brewer color palette "Dark2"
ggsurvplot(fit, linetype = "strata", 
           conf.int = TRUE, pval = TRUE,
           palette = "Dark2")</code></pre>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/survminer/surminer-ggplot2-survival-plot-line-types-colors-2.png" title="" alt="" width="518.4" /></p>
<pre class="r"><code># Use grey palette
ggsurvplot(fit, linetype = "strata", 
           conf.int = TRUE, pval = TRUE,
           palette = "grey")</code></pre>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/survminer/surminer-ggplot2-survival-plot-line-types-colors-3.png" title="" alt="" width="518.4" /></p>
</div>
<div id="add-number-at-risk-table" class="section level3">
<h3>Add number at risk table</h3>
<pre class="r"><code># Add risk table
# and change risk table y text colors by strata
ggsurvplot(fit, pval = TRUE, conf.int = TRUE,
           risk.table = TRUE, risk.table.y.text.col = TRUE)</code></pre>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/survminer/surminer-ggplot2-survival-curves-risk-table-1.png" title="" alt="" width="518.4" /></p>
<pre class="r"><code># Customize the output and then print
res <- ggsurvplot(fit, pval = TRUE, conf.int = TRUE,
           risk.table = TRUE)
res$table <- res$table + theme(axis.line = element_blank())
res$plot <- res$plot + labs(title = "Survival Curves")
print(res)</code></pre>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/survminer/surminer-ggplot2-survival-curves-risk-table-2.png" title="" alt="" width="518.4" /></p>
<pre class="r"><code># Change color, linetype by strata, risk.table color by strata
ggsurvplot(fit, 
           pval = TRUE, conf.int = TRUE,
           risk.table = TRUE, # Add risk table
           risk.table.col = "strata", # Change risk table color by groups
           linetype = "strata", # Change line type by groups
           ggtheme = theme_bw(), # Change ggplot2 theme
           palette = c("#E7B800", "#2E9FDF"))</code></pre>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/survminer/surminer-ggplot2-survival-curves-risk-table-3.png" title="" alt="" width="518.4" /></p>
</div>
<div id="change-x-axis-limits" class="section level3">
<h3>Change x axis limits</h3>
<pre class="r"><code># Change x axis limits (xlim)
#++++++++++++++++++++++++++++++++++++
# One would like to cut axes at a specific time point
ggsurvplot(fit, 
           pval = TRUE, conf.int = TRUE,
           risk.table = TRUE, # Add risk table
           risk.table.col = "strata", # Change risk table color by groups
           ggtheme = theme_bw(), # Change ggplot2 theme
           palette = "Dark2",
           xlim = c(0, 600))</code></pre>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/survminer/surminer-ggplot2-survival-curves-xlim-1.png" title="" alt="" width="518.4" /></p>
</div>
<div id="transform-survival-curves-plot-cumulative-events-and-hazard-function" class="section level3">
<h3>Transform survival curves: plot cumulative events and hazard function</h3>
<pre class="r"><code># Plot cumulative events
ggsurvplot(fit, conf.int = TRUE,
           palette = c("#FF9E29", "#86AA00"),
           risk.table = TRUE, risk.table.col = "strata",
           fun = "event")</code></pre>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/survminer/surminer-ggplot2-survival-curves-transformation-1.png" title="" alt="" width="518.4" /></p>
<pre class="r"><code># Plot the cumulative hazard function
ggsurvplot(fit, conf.int = TRUE, 
           palette = c("#FF9E29", "#86AA00"),
           risk.table = TRUE, risk.table.col = "strata",
           fun = "cumhaz")</code></pre>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/survminer/surminer-ggplot2-survival-curves-transformation-2.png" title="" alt="" width="518.4" /></p>
<pre class="r"><code># Arbitrary function
ggsurvplot(fit, conf.int = TRUE, 
          palette = c("#FF9E29", "#86AA00"),
           risk.table = TRUE, risk.table.col = "strata",
           pval = TRUE,
           fun = function(y) y*100)</code></pre>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/survminer/surminer-ggplot2-survival-curves-transformation-3.png" title="" alt="" width="518.4" /></p>
</div>
</div>
<div id="survival-curves-with-multiple-groups" class="section level2">
<h2>Survival curves with multiple groups</h2>
<pre class="r"><code># Fit (complexe) survival curves
#++++++++++++++++++++++++++++++++++++

require("survival")
fit2 <- survfit( Surv(time, status) ~ rx + adhere,
    data = colon )

# Visualize
#++++++++++++++++++++++++++++++++++++

# Visualize: add p-value, chang y limits
# change color using brewer palette
ggsurvplot(fit2, pval = TRUE, 
           break.time.by = 800,
           risk.table = TRUE,
           risk.table.height = 0.5#Useful when you have multiple groups
           )</code></pre>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/survminer/surminer-gplot2-survival-curves-multiple-groups-1.png" title="" alt="" width="537.6" /></p>
<pre class="r"><code># Adjust risk table and survival plot heights
# ++++++++++++++++++++++++++++++++++++
# Risk table height
ggsurvplot(fit2, pval = TRUE,
          break.time.by = 800,
          risk.table = TRUE,
          risk.table.col = "strata",
          risk.table.height = 0.5, 
          palette = "Dark2")</code></pre>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/survminer/surminer-gplot2-survival-curves-multiple-groups-2.png" title="" alt="" width="537.6" /></p>
<pre class="r"><code># Change legend labels
# ++++++++++++++++++++++++++++++++++++

ggsurvplot(fit2, pval = TRUE, 
           break.time.by = 800,
           risk.table = TRUE,
           risk.table.col = "strata",
           risk.table.height = 0.5, 
           ggtheme = theme_bw(),
           legend.labs = c("A", "B", "C", "D", "E", "F"))</code></pre>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/survminer/surminer-gplot2-survival-curves-multiple-groups-3.png" title="" alt="" width="537.6" /></p>
</div>
</div>
<div id="infos" class="section level1">
<h1>Infos</h1>
<p>This article was built with:</p>
<pre><code>##  setting  value                       
##  version  R version 3.2.3 (2015-12-10)
##  system   x86_64, darwin13.4.0        
##  ui       X11                         
##  language (EN)                        
##  collate  fr_FR.UTF-8                 
##  tz       Europe/Paris                
##  date     2016-02-21                  
## 
##  package      * version date       source        
##  colorspace     1.2-6   2015-03-11 CRAN (R 3.2.0)
##  dichromat      2.0-0   2013-01-24 CRAN (R 3.2.0)
##  digest         0.6.9   2016-01-08 CRAN (R 3.2.3)
##  ggplot2      * 2.0.0   2015-12-18 CRAN (R 3.2.3)
##  gridExtra      2.0.0   2015-07-14 CRAN (R 3.2.0)
##  gtable         0.1.2   2012-12-05 CRAN (R 3.2.0)
##  labeling       0.3     2014-08-23 CRAN (R 3.2.0)
##  magrittr       1.5     2014-11-22 CRAN (R 3.2.0)
##  MASS           7.3-45  2015-11-10 CRAN (R 3.2.3)
##  munsell        0.4.3   2016-02-13 CRAN (R 3.2.3)
##  plyr           1.8.3   2015-06-12 CRAN (R 3.2.0)
##  RColorBrewer   1.1-2   2014-12-07 CRAN (R 3.2.0)
##  Rcpp           0.12.3  2016-01-10 CRAN (R 3.2.3)
##  reshape2       1.4.1   2014-12-06 CRAN (R 3.2.0)
##  scales         0.3.0   2015-08-25 CRAN (R 3.2.0)
##  stringi        1.0-1   2015-10-22 CRAN (R 3.2.0)
##  stringr        1.0.0   2015-04-30 CRAN (R 3.2.0)
##  survival     * 2.38-3  2015-07-02 CRAN (R 3.2.3)
##  survminer    * 0.2.0   2016-02-18 CRAN (R 3.2.3)</code></pre>
</div>

<script>jQuery(document).ready(function () {
    jQuery('h1').addClass('wiki_paragraph1');
    jQuery('h2').addClass('wiki_paragraph2');
    jQuery('h3').addClass('wiki_paragraph3');
    jQuery('h4').addClass('wiki_paragraph4');
    });//add phpboost class to header</script>
<style>.content{padding:0px;}</style>
</div><!--end rdoc-->
<!--====================== stop here when you copy to sthda================-->



<!-- END HTML -->]]></description>
			<pubDate>Sun, 21 Feb 2016 21:15:04 +0100</pubDate>
			
		</item>
		
	</channel>
</rss>
