<p><div><div><div><div data-width="100" data-show-faces="false" data-send="true" data-layout="button_count" data-height="21" data-href="https://www.r-bloggers.com/when-you-went-too-far-with-survival-plots-during-the-survminer-1st-anniversary/"></div></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="http://r-addict.com/2017/01/15/Too-Far-With-Survival-Plots.html"> http://r-addict.com</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<p><img src="https://i2.wp.com/r-addict.com/images/fulls/uber-survminer.png?w=456" data-recalc-dims="1"> We are celebrating the 1st anniversary of the survminer’s release on CRAN! Due to that fact I have prepared the most (uber platinum) customized survival plot that I could imagine. I went too far because it took over 30 parameters to create a graph..</p>
<p><a target="_blank" rel="nofollow" href="https://cran.r-project.org/web/packages/survminer/index.html">survminer</a>, a package for drawing easily beautiful and ‘ready-to-publish’ survival curves with the ‘number at risk’ table and ‘censoring count plot’, has became very popular at the end of a previous year. It happend due to 3 great methodology posts about Cox Proportional Hazards model and Survival Analysis basics by Alboukadel Kassambara (<a target="_blank" rel="nofollow" href="https://github.com/kassambara/">kassambara</a>) published on <a target="_blank" rel="nofollow" href="http://www.sthda.com/english/">STDHA</a></p>
<ul>
<li><a target="_blank" rel="nofollow" href="http://www.sthda.com/english/wiki/survival-analysis-basics">Survival Analysisc Basics</a></li>
<li><a target="_blank" rel="nofollow" href="http://www.sthda.com/english/wiki/cox-proportional-hazards-model">Cox Proportional Hazards Model</a></li>
<li><a target="_blank" rel="nofollow" href="http://www.sthda.com/english/wiki/cox-model-assumptions">Cox Model Assumptions</a></li>
</ul>
<p>If you are working in the survival analysis field, you might be interested in reading the post covering the newest features in survminer: <a target="_blank" rel="nofollow" href="http://www.sthda.com/english/wiki/survminer-0-2-4">survminer 0.2.4</a></p>
<p>Right now, after a year of the first CRAN release, survminer has been downloaded <a target="_blank" rel="nofollow" href="https://cranlogs.r-pkg.org/badges/grand-total/survminer">11k times</a> and has been used and cited in several research articles:</p>
<ul>
<li><a target="_blank" rel="nofollow" href="http://cancerdiscovery.aacrjournals.org/content/candisc/early/2016/12/01/2159-8290.CD-16-1223.full.pdf">Primary resistance to PD-1 blockade mediated by JAK1/2 mutations</a></li>
<li><a target="_blank" rel="nofollow" href="https://www.jmir.org/2016/11/e301">Methods for Evaluating Respondent Attrition in Web-Based Surveys</a></li>
<li><a target="_blank" rel="nofollow" href="https://www.ncbi.nlm.nih.gov/pmc/articles/PMC5067898/#CR18">Antiretroviral therapy improves survival among TB-HIV co-infected patients who have CD4+ T-cell count above 350cells/mm3</a></li>
<li><a target="_blank" rel="nofollow" href="https://www.ncbi.nlm.nih.gov/pubmed/27576078">The serological response against foot and mouth disease virus elicited by repeated vaccination of dairy cattl</a></li>
<li><a target="_blank" rel="nofollow" href="https://www.researchgate.net/publication/307559129_The_serological_response_against_foot_and_mouth_disease_virus_elicited_by_repeated_vaccination_of_dairy_cattle">The serological response against foot and mouth disease virus elicited by repeated vaccination of dairy cattle</a></li>
<li><a target="_blank" rel="nofollow" href="activiteen:%20A%20Protocol%20for%20Deployment%20of%20a%20Consumer%20Wearable%20Device%20in%20an%20Academic%20Setting">ActiviTeen: A Protocol for Deployment of a Consumer Wearable Device in an Academic Setting</a></li>
</ul>
<p>Due to the celebration of it’s 1st anniversary on CRAN, I have prepared a long survival graph of Kaplan-Meier estimates of survival curves, where each option is described below. I think I went too far to present the possible customization of the graph because this example takes over 30 parameters!</p>
<p>
<br>
<div class="feedlyNoScript">
<pre>
       
<figure><pre><code data-lang="r"><span> </span><span>ggsurvplot</span><span>(</span><span>
</span><span>fit</span><span>,</span><span> </span><span># survfit object with calculated statistics.
</span><span> </span><span>risk.table</span><span> </span><span>=</span><span> </span><span>TRUE</span><span>,</span><span> </span><span># show risk table.
</span><span> </span><span>pval</span><span> </span><span>=</span><span> </span><span>TRUE</span><span>,</span><span> </span><span># show p-value of log-rank test.
</span><span> </span><span>conf.int</span><span> </span><span>=</span><span> </span><span>TRUE</span><span>,</span><span> </span><span># show confidence intervals for </span><span> </span><span># point estimaes of survival curves.
</span><span> </span><span>xlim</span><span> </span><span>=</span><span> </span><span>c</span><span>(</span><span>0</span><span>,</span><span>500</span><span>),</span><span> </span><span># present narrower X axis, but not affect
</span><span> </span><span># survival estimates.
</span><span> </span><span>xlab</span><span> </span><span>=</span><span> </span><span>&quot;Time in days&quot;</span><span>,</span><span> </span><span># customize X axis label.
</span><span> </span><span>break.time.by</span><span> </span><span>=</span><span> </span><span>100</span><span>,</span><span> </span><span># break X axis in time intervals by 500.
</span><span> </span><span>ggtheme</span><span> </span><span>=</span><span> </span><span>theme_light</span><span>(),</span><span> </span><span># customize plot and risk table with a theme.
</span><span> </span><span>risk.table.y.text.col</span><span> </span><span>=</span><span> </span><span>T</span><span>,</span><span># colour risk table text annotations.
</span><span> </span><span>risk.table.y.text</span><span> </span><span>=</span><span> </span><span>FALSE</span><span>,</span><span># show bars instead of names in text annotations
</span><span> </span><span># in legend of risk table.
</span><span> </span><span>ncensor.plot</span><span> </span><span>=</span><span> </span><span>TRUE</span><span>,</span><span> </span><span># plot the number of censored subjects at time t
</span><span> </span><span>conf.int.style</span><span> </span><span>=</span><span> </span><span>&quot;step&quot;</span><span>,</span><span> </span><span># customize style of confidence intervals
</span><span> </span><span>surv.median.line</span><span> </span><span>=</span><span> </span><span>&quot;hv&quot;</span><span>,</span><span> </span><span># add the median survival pointer.
</span><span> </span><span>legend.labs</span><span> </span><span>=</span><span> </span><span>c</span><span>(</span><span>&quot;Male&quot;</span><span>,</span><span> </span><span>&quot;Female&quot;</span><span>),</span><span> </span><span># change legend labels.
</span><span> </span><span>palette</span><span> </span><span>=</span><span> </span><span>c</span><span>(</span><span>&quot;#E7B800&quot;</span><span>,</span><span> </span><span>&quot;#2E9FDF&quot;</span><span>),</span><span># custom color palettes.
</span><span> </span><span>main</span><span> </span><span>=</span><span> </span><span>&quot;Survival curves&quot;</span><span>,</span><span> </span><span># specify the title of the plot
</span><span> </span><span>submain</span><span> </span><span>=</span><span> </span><span>&quot;Based on Kaplan-Meier estimates&quot;</span><span>,</span><span> </span><span># the subtitle of the plot </span><span> </span><span>caption</span><span> </span><span>=</span><span> </span><span>&quot;created with survminer&quot;</span><span>,</span><span> </span><span># the caption of the plot
</span><span> </span><span>font.main</span><span> </span><span>=</span><span> </span><span>c</span><span>(</span><span>16</span><span>,</span><span> </span><span>&quot;bold&quot;</span><span>,</span><span> </span><span>&quot;darkblue&quot;</span><span>),</span><span> </span><span># font for titles of the plot, the table and censor part
</span><span> </span><span>font.submain</span><span> </span><span>=</span><span> </span><span>c</span><span>(</span><span>15</span><span>,</span><span> </span><span>&quot;bold.italic&quot;</span><span>,</span><span> </span><span>&quot;purple&quot;</span><span>),</span><span> </span><span># font for subtitles in the plot, the table and censor part
</span><span> </span><span>font.caption</span><span> </span><span>=</span><span> </span><span>c</span><span>(</span><span>14</span><span>,</span><span> </span><span>&quot;plain&quot;</span><span>,</span><span> </span><span>&quot;orange&quot;</span><span>),</span><span> </span><span># font for captions in the plot, the table and censor part
</span><span> </span><span>font.x</span><span> </span><span>=</span><span> </span><span>c</span><span>(</span><span>14</span><span>,</span><span> </span><span>&quot;bold.italic&quot;</span><span>,</span><span> </span><span>&quot;red&quot;</span><span>),</span><span> </span><span># font for x axises in the plot, the table and censor part
</span><span> </span><span>font.y</span><span> </span><span>=</span><span> </span><span>c</span><span>(</span><span>14</span><span>,</span><span> </span><span>&quot;bold.italic&quot;</span><span>,</span><span> </span><span>&quot;darkred&quot;</span><span>),</span><span> </span><span># font for y axises in the plot, the table and censor part
</span><span> </span><span>font.tickslab</span><span> </span><span>=</span><span> </span><span>c</span><span>(</span><span>12</span><span>,</span><span> </span><span>&quot;plain&quot;</span><span>,</span><span> </span><span>&quot;darkgreen&quot;</span><span>),</span><span> </span><span># font for ticklabs in the plot, the table and censor part
</span><span> </span><span>########## risk table #########,
</span><span> </span><span>risk.table.title</span><span> </span><span>=</span><span> </span><span>&quot;Note the risk set sizes&quot;</span><span>,</span><span> </span><span># the title of the risk table
</span><span> </span><span>risk.table.subtitle</span><span> </span><span>=</span><span> </span><span>&quot;and remember about censoring.&quot;</span><span>,</span><span> </span><span># the subtitle of the risk table
</span><span> </span><span>risk.table.caption</span><span> </span><span>=</span><span> </span><span>&quot;source code: website.com&quot;</span><span>,</span><span> </span><span># the caption of the risk table
</span><span> </span><span>risk.table.height</span><span> </span><span>=</span><span> </span><span>0.35</span><span>,</span><span> </span><span># the height of the risk table
</span><span> </span><span>########## ncensor plot ######
</span><span> </span><span>ncensor.plot.title</span><span> </span><span>=</span><span> </span><span>&quot;Number of censorings&quot;</span><span>,</span><span> </span><span># as above but for the censoring plot
</span><span> </span><span>ncensor.plot.subtitle</span><span> </span><span>=</span><span> </span><span>&quot;over the time.&quot;</span><span>,</span><span>
</span><span>ncensor.plot.caption</span><span> </span><span>=</span><span> </span><span>&quot;data available at data.com&quot;</span><span>,</span><span>
</span><span>ncensor.plot.height</span><span> </span><span>=</span><span> </span><span>0.35</span><span>)</span><span>
</span></code></pre>
</figure>
<p> </p>

<p>
<div>
<div>To <strong>leave a comment</strong> for the author, please follow the link and comment on their blog: <strong><a href="http://r-addict.com/2017/01/15/Too-Far-With-Survival-Plots.html"> http://r-addict.com</a></strong>.</div>
<hr>
<a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers.com</a> offers <strong><a rel="nofollow" href="https://feedburner.google.com/fb/a/mailverify?uri=RBloggers">daily e-mail updates</a></strong> about <a title="The R Project for Statistical Computing" rel="nofollow" href="https://www.r-project.org/">R</a> news and <a title="R tutorials" rel="nofollow" href="https://www.r-bloggers.com/search/tutorial">tutorials</a> on topics such as: <a title="Data science" rel="nofollow" href="https://www.r-bloggers.com/search/data%20science">Data science</a>, <a title="Big Data" rel="nofollow" href="https://www.r-bloggers.com/search/Big%20Data">Big Data, <a title="R jobs" rel="nofollow" href="https://www.r-users.com/">R jobs</a>, visualization (<a title="ggplot and ggplot2 tutorials" rel="nofollow" href="https://www.r-bloggers.com/search/ggplot2">ggplot2</a>, <a title="Boxplots using lattice and ggplot2 tutorials" rel="nofollow" href="https://www.r-bloggers.com/search/boxplot">Boxplots</a>, <a title="Maps and gis" rel="nofollow" href="https://www.r-bloggers.com/search/map">maps</a>, <a title="Animation in R" rel="nofollow" href="https://www.r-bloggers.com/search/animation">animation</a>), programming (<a title="RStudio IDE for R" rel="nofollow" href="https://www.r-bloggers.com/search/RStudio">RStudio</a>, <a title="Sweave and literate programming" rel="nofollow" href="https://www.r-bloggers.com/search/sweave">Sweave</a>, <a title="LaTeX in R" rel="nofollow" href="https://www.r-bloggers.com/search/LaTeX">LaTeX</a>, <a title="SQL and databases" rel="nofollow" href="https://www.r-bloggers.com/search/SQL">SQL</a>, <a title="Eclipse IDE for R" rel="nofollow" href="https://www.r-bloggers.com/search/eclipse">Eclipse</a>, <a title="git and github, Version Control System" rel="nofollow" href="https://www.r-bloggers.com/search/git">git</a>, <a title="Large data in R using Hadoop" rel="nofollow" href="https://www.r-bloggers.com/search/hadoop">hadoop</a>, <a title="Web Scraping of google, facebook, yahoo, twitter and more using R" rel="nofollow" href="https://www.r-bloggers.com/search/Web+Scraping">Web Scraping</a>) statistics (<a title="Regressions and ANOVA analysis tutorials" rel="nofollow" href="https://www.r-bloggers.com/search/regression">regression</a>, <a title="principal component analysis tutorial" rel="nofollow" href="https://www.r-bloggers.com/search/PCA">PCA</a>, <a title="Time series" rel="nofollow" href="https://www.r-bloggers.com/search/time+series">time series</a>, <a title="finance trading" rel="nofollow" href="https://www.r-bloggers.com/search/trading">trading</a>) and more...
<img height="1" alt="" width="1" src="http://feeds.feedburner.com/~r/RBloggers/~4/bDBHYSP6zAM"></a></div></pre></div>