<!DOCTYPE html>
<!-- Generated by pkgdown: do not edit by hand --><html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Polar plot for survival and correlation connection • ggpolar</title>
<!-- jquery --><script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.1/jquery.min.js" integrity="sha256-CSXorXvZcTkaix6Yvo6HppcZGetbYMGWSFlBw8HfCJo=" crossorigin="anonymous"></script><!-- Bootstrap --><link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.4.1/css/bootstrap.min.css" integrity="sha256-bZLfwXAP04zRMK2BjiO8iu9pf4FbLqX6zitd+tIvLhE=" crossorigin="anonymous">
<script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.4.1/js/bootstrap.min.js" integrity="sha256-nuL8/2cJ5NDSSwnKD8VqreErSWHtnEP9E7AySL+1ev4=" crossorigin="anonymous"></script><!-- bootstrap-toc --><link rel="stylesheet" href="../bootstrap-toc.css">
<script src="../bootstrap-toc.js"></script><!-- Font Awesome icons --><link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.12.1/css/all.min.css" integrity="sha256-mmgLkCYLUQbXn0B1SRqzHar6dCnv9oZFPEC1g1cwlkk=" crossorigin="anonymous">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.12.1/css/v4-shims.min.css" integrity="sha256-wZjR52fzng1pJHwx4aV2AO3yyTOXrcDW7jBpJtTwVxw=" crossorigin="anonymous">
<!-- clipboard.js --><script src="https://cdnjs.cloudflare.com/ajax/libs/clipboard.js/2.0.6/clipboard.min.js" integrity="sha256-inc5kl9MA1hkeYUt+EC3BhlIgyp/2jDIyBLS6k3UxPI=" crossorigin="anonymous"></script><!-- headroom.js --><script src="https://cdnjs.cloudflare.com/ajax/libs/headroom/0.11.0/headroom.min.js" integrity="sha256-AsUX4SJE1+yuDu5+mAVzJbuYNPHj/WroHuZ8Ir/CkE0=" crossorigin="anonymous"></script><script src="https://cdnjs.cloudflare.com/ajax/libs/headroom/0.11.0/jQuery.headroom.min.js" integrity="sha256-ZX/yNShbjqsohH1k95liqY9Gd8uOiE1S4vZc+9KQ1K4=" crossorigin="anonymous"></script><!-- pkgdown --><link href="../pkgdown.css" rel="stylesheet">
<script src="../pkgdown.js"></script><meta property="og:title" content="Polar plot for survival and correlation connection">
<meta property="og:description" content="ggpolar">
<!-- mathjax --><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js" integrity="sha256-nvJJv9wWKEm88qvoQl9ekL2J+k/RWIsaSScxxlsrv8k=" crossorigin="anonymous"></script><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/config/TeX-AMS-MML_HTMLorMML.js" integrity="sha256-84DKXVJXs0/F8OTMzX4UR909+jtl4G7SPypPavF+GfA=" crossorigin="anonymous"></script><!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<![endif]-->
</head>
<body data-spy="scroll" data-target="#toc">
    <div class="container template-article">
      <header><div class="navbar navbar-default navbar-fixed-top" role="navigation">
  <div class="container">
    <div class="navbar-header">
      <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false">
        <span class="sr-only">Toggle navigation</span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
      </button>
      <span class="navbar-brand">
        <a class="navbar-link" href="../index.html">ggpolar</a>
        <span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Released version">0.2.1</span>
      </span>
    </div>

    <div id="navbar" class="navbar-collapse collapse">
      <ul class="nav navbar-nav">
<li>
  <a href="../index.html">
    <span class="fas fa-home fa-lg"></span>
     
  </a>
</li>
<li>
  <a href="../reference/index.html">Reference</a>
</li>
<li class="dropdown">
  <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false">
    Articles
     
    <span class="caret"></span>
  </a>
  <ul class="dropdown-menu" role="menu">
<li>
      <a href="../articles/surv-corr-connection.html">Polar plot for survival and correlation connection</a>
    </li>
  </ul>
</li>
      </ul>
<ul class="nav navbar-nav navbar-right">
<li>
  <a href="https://github.com/ShixiangWang/polar/">
    <span class="fab fa-github fa-lg"></span>
     
  </a>
</li>
      </ul>
</div>
<!--/.nav-collapse -->
  </div>
<!--/.container -->
</div>
<!--/.navbar -->

      

      </header><script src="surv-corr-connection_files/header-attrs-2.11/header-attrs.js"></script><div class="row">
  <div class="col-md-9 contents">
    <div class="page-header toc-ignore">
      <h1 data-toc-skip>Polar plot for survival and correlation connection</h1>
            
      
      <small class="dont-index">Source: <a href="https://github.com/ShixiangWang/polar/blob/master/vignettes/surv-corr-connection.Rmd"><code>vignettes/surv-corr-connection.Rmd</code></a></small>
      <div class="hidden name"><code>surv-corr-connection.Rmd</code></div>

    </div>

    
    
<div class="sourceCode" id="cb1"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span class="kw"><a href="https://rdrr.io/r/base/library.html">library</a></span><span class="op">(</span><span class="va"><a href="https://github.com/ShixiangWang/polar">ggpolar</a></span><span class="op">)</span>
<span class="co">#&gt; Loading required package: ggplot2</span>
<span class="kw"><a href="https://rdrr.io/r/base/library.html">library</a></span><span class="op">(</span><span class="va"><a href="https://github.com/therneau/survival">survival</a></span><span class="op">)</span>
<span class="kw"><a href="https://rdrr.io/r/base/library.html">library</a></span><span class="op">(</span><span class="va"><a href="https://github.com/ShixiangWang/ezcox">ezcox</a></span><span class="op">)</span>
<span class="co">#&gt; Welcome to 'ezcox' package!</span>
<span class="co">#&gt; =======================================================================</span>
<span class="co">#&gt; You are using ezcox version 1.0.2</span>
<span class="co">#&gt; </span>
<span class="co">#&gt; Project home : https://github.com/ShixiangWang/ezcox</span>
<span class="co">#&gt; Documentation: https://shixiangwang.github.io/ezcox</span>
<span class="co">#&gt; Cite as      : arXiv:2110.14232</span>
<span class="co">#&gt; =======================================================================</span>
<span class="co">#&gt; </span></code></pre></div>
<div class="sourceCode" id="cb2"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span class="va">data</span> <span class="op">=</span> <span class="fu">survival</span><span class="fu">::</span><span class="va"><a href="https://rdrr.io/pkg/survival/man/lung.html">lung</a></span>
<span class="fu"><a href="https://rdrr.io/r/utils/head.html">head</a></span><span class="op">(</span><span class="va">data</span><span class="op">)</span>
<span class="co">#&gt;   inst time status age sex ph.ecog ph.karno pat.karno meal.cal wt.loss</span>
<span class="co">#&gt; 1    3  306      2  74   1       1       90       100     1175      NA</span>
<span class="co">#&gt; 2    3  455      2  68   1       0       90        90     1225      15</span>
<span class="co">#&gt; 3    3 1010      1  56   1       0       90        90       NA      15</span>
<span class="co">#&gt; 4    5  210      2  57   1       1       90        60     1150      11</span>
<span class="co">#&gt; 5    1  883      2  60   1       0      100        90       NA       0</span>
<span class="co">#&gt; 6   12 1022      1  74   1       1       50        80      513       0</span></code></pre></div>
<p>Pick several variables.</p>
<div class="sourceCode" id="cb3"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span class="va">vars</span> <span class="op">=</span> <span class="fu"><a href="https://rdrr.io/r/base/c.html">c</a></span><span class="op">(</span><span class="st">"age"</span>, <span class="st">"sex"</span>, <span class="st">"ph.ecog"</span>, <span class="st">"ph.karno"</span>, <span class="st">"pat.karno"</span>, <span class="st">"meal.cal"</span>, <span class="st">"wt.loss"</span><span class="op">)</span></code></pre></div>
<div id="univariable-cox-analysis" class="section level3">
<h3 class="hasAnchor">
<a href="#univariable-cox-analysis" class="anchor"></a>Univariable Cox analysis</h3>
<div class="sourceCode" id="cb4"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span class="va">df_cox</span> <span class="op">=</span> <span class="fu"><a href="https://rdrr.io/pkg/ezcox/man/ezcox.html">ezcox</a></span><span class="op">(</span><span class="va">data</span>, <span class="va">vars</span><span class="op">)</span>
<span class="va">df_cox</span>
<span class="co">#&gt; # A tibble: 7 × 12</span>
<span class="co">#&gt;   Variable  is_control contrast_level ref_level n_contrast n_ref      beta    HR</span>
<span class="co">#&gt;   &lt;chr&gt;     &lt;lgl&gt;      &lt;chr&gt;          &lt;chr&gt;          &lt;int&gt; &lt;int&gt;     &lt;dbl&gt; &lt;dbl&gt;</span>
<span class="co">#&gt; 1 age       FALSE      age            age              228   228  0.0187   1.02 </span>
<span class="co">#&gt; 2 sex       FALSE      sex            sex              228   228 -0.531    0.588</span>
<span class="co">#&gt; 3 ph.ecog   FALSE      ph.ecog        ph.ecog          227   227  0.476    1.61 </span>
<span class="co">#&gt; 4 ph.karno  FALSE      ph.karno       ph.karno         227   227 -0.0164   0.984</span>
<span class="co">#&gt; 5 pat.karno FALSE      pat.karno      pat.karno        225   225 -0.0199   0.98 </span>
<span class="co">#&gt; 6 meal.cal  FALSE      meal.cal       meal.cal         181   181 -0.000124 1    </span>
<span class="co">#&gt; 7 wt.loss   FALSE      wt.loss        wt.loss          214   214  0.00132  1    </span>
<span class="co">#&gt; # … with 4 more variables: lower_95 &lt;dbl&gt;, upper_95 &lt;dbl&gt;, p.value &lt;dbl&gt;,</span>
<span class="co">#&gt; #   global.pval &lt;dbl&gt;</span></code></pre></div>
</div>
<div id="correlation-analysis" class="section level3">
<h3 class="hasAnchor">
<a href="#correlation-analysis" class="anchor"></a>Correlation analysis</h3>
<div class="sourceCode" id="cb5"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span class="va">vars_comb</span> <span class="op">=</span> <span class="fu"><a href="https://rdrr.io/r/utils/combn.html">combn</a></span><span class="op">(</span><span class="va">vars</span>, <span class="fl">2</span>, simplify <span class="op">=</span> <span class="cn">FALSE</span><span class="op">)</span>
<span class="va">cor_value</span> <span class="op">=</span> <span class="fu"><a href="https://rdrr.io/r/base/lapply.html">sapply</a></span><span class="op">(</span><span class="va">vars_comb</span>, <span class="kw">function</span><span class="op">(</span><span class="va">x</span><span class="op">)</span> <span class="op">{</span>
  <span class="fu"><a href="https://rdrr.io/r/stats/cor.html">cor</a></span><span class="op">(</span><span class="va">data</span><span class="op">[[</span><span class="va">x</span><span class="op">[</span><span class="fl">1</span><span class="op">]</span><span class="op">]</span><span class="op">]</span>, <span class="va">data</span><span class="op">[[</span><span class="va">x</span><span class="op">[</span><span class="fl">2</span><span class="op">]</span><span class="op">]</span><span class="op">]</span>, use <span class="op">=</span> <span class="st">"pairwise"</span><span class="op">)</span>
<span class="op">}</span><span class="op">)</span>

<span class="va">df_cor</span> <span class="op">=</span> <span class="fu"><a href="https://rdrr.io/r/base/cbind.html">cbind</a></span><span class="op">(</span><span class="fu"><a href="https://rdrr.io/r/base/as.data.frame.html">as.data.frame</a></span><span class="op">(</span><span class="fu"><a href="https://rdrr.io/r/base/t.html">t</a></span><span class="op">(</span><span class="fu"><a href="https://rdrr.io/r/base/lapply.html">sapply</a></span><span class="op">(</span><span class="va">vars_comb</span>, <span class="kw">function</span><span class="op">(</span><span class="va">x</span><span class="op">)</span> <span class="va">x</span><span class="op">)</span><span class="op">)</span><span class="op">)</span>, <span class="va">cor_value</span><span class="op">)</span>
<span class="fu"><a href="https://rdrr.io/r/base/colnames.html">colnames</a></span><span class="op">(</span><span class="va">df_cor</span><span class="op">)</span> <span class="op">=</span> <span class="fu"><a href="https://rdrr.io/r/base/c.html">c</a></span><span class="op">(</span><span class="st">"var1"</span>, <span class="st">"var2"</span>, <span class="st">"correlation"</span><span class="op">)</span>
<span class="va">df_cor</span><span class="op">$</span><span class="va">size</span> <span class="op">=</span> <span class="fu"><a href="https://rdrr.io/r/base/MathFun.html">abs</a></span><span class="op">(</span><span class="va">df_cor</span><span class="op">$</span><span class="va">correlation</span><span class="op">)</span>
<span class="va">df_cor</span><span class="op">$</span><span class="va">way</span> <span class="op">=</span> <span class="fu"><a href="https://rdrr.io/r/base/ifelse.html">ifelse</a></span><span class="op">(</span><span class="va">df_cor</span><span class="op">$</span><span class="va">correlation</span> <span class="op">&gt;</span> <span class="fl">0</span>, <span class="st">"positive"</span>, <span class="st">"negative"</span><span class="op">)</span>
<span class="va">df_cor</span>
<span class="co">#&gt;         var1      var2 correlation       size      way</span>
<span class="co">#&gt; 1        age       sex -0.12216709 0.12216709 negative</span>
<span class="co">#&gt; 2        age   ph.ecog  0.19323604 0.19323604 positive</span>
<span class="co">#&gt; 3        age  ph.karno -0.20318207 0.20318207 negative</span>
<span class="co">#&gt; 4        age pat.karno -0.12616688 0.12616688 negative</span>
<span class="co">#&gt; 5        age  meal.cal -0.23141071 0.23141071 negative</span>
<span class="co">#&gt; 6        age   wt.loss  0.03814787 0.03814787 positive</span>
<span class="co">#&gt; 7        sex   ph.ecog -0.02060379 0.02060379 negative</span>
<span class="co">#&gt; 8        sex  ph.karno  0.01138505 0.01138505 positive</span>
<span class="co">#&gt; 9        sex pat.karno  0.04607145 0.04607145 positive</span>
<span class="co">#&gt; 10       sex  meal.cal -0.16835976 0.16835976 negative</span>
<span class="co">#&gt; 11       sex   wt.loss -0.12907708 0.12907708 negative</span>
<span class="co">#&gt; 12   ph.ecog  ph.karno -0.80726666 0.80726666 negative</span>
<span class="co">#&gt; 13   ph.ecog pat.karno -0.51122086 0.51122086 negative</span>
<span class="co">#&gt; 14   ph.ecog  meal.cal -0.09851018 0.09851018 negative</span>
<span class="co">#&gt; 15   ph.ecog   wt.loss  0.18758944 0.18758944 positive</span>
<span class="co">#&gt; 16  ph.karno pat.karno  0.52029737 0.52029737 positive</span>
<span class="co">#&gt; 17  ph.karno  meal.cal  0.04223324 0.04223324 positive</span>
<span class="co">#&gt; 18  ph.karno   wt.loss -0.17543452 0.17543452 negative</span>
<span class="co">#&gt; 19 pat.karno  meal.cal  0.16575874 0.16575874 positive</span>
<span class="co">#&gt; 20 pat.karno   wt.loss -0.17199064 0.17199064 negative</span>
<span class="co">#&gt; 21  meal.cal   wt.loss -0.10257242 0.10257242 negative</span></code></pre></div>
</div>
<div id="visualization" class="section level3">
<h3 class="hasAnchor">
<a href="#visualization" class="anchor"></a>Visualization</h3>
<div class="sourceCode" id="cb6"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span class="va">df_cox</span><span class="op">$</span><span class="va">role</span> <span class="op">=</span> <span class="fu"><a href="https://rdrr.io/r/base/ifelse.html">ifelse</a></span><span class="op">(</span>
  <span class="va">df_cox</span><span class="op">$</span><span class="va">p.value</span> <span class="op">&gt;</span> <span class="fl">0.05</span>, <span class="st">"non-signf"</span>,
  <span class="fu"><a href="https://rdrr.io/r/base/ifelse.html">ifelse</a></span><span class="op">(</span><span class="va">df_cox</span><span class="op">$</span><span class="va">HR</span> <span class="op">&lt;</span> <span class="fl">1</span>, <span class="st">"protector"</span>, <span class="st">"risker"</span><span class="op">)</span>
<span class="op">)</span>
<span class="va">df_cox</span><span class="op">$</span><span class="va">`-log10(p)`</span> <span class="op">=</span> <span class="op">-</span><span class="fu"><a href="https://rdrr.io/r/base/Log.html">log10</a></span><span class="op">(</span><span class="va">df_cox</span><span class="op">$</span><span class="va">p.value</span><span class="op">)</span></code></pre></div>
<div class="sourceCode" id="cb7"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span class="va">p</span> <span class="op">=</span> <span class="fu"><a href="../reference/polar_init.html">polar_init</a></span><span class="op">(</span><span class="va">df_cox</span>, x <span class="op">=</span> <span class="va">Variable</span>, <span class="fu"><a href="https://ggplot2.tidyverse.org/reference/aes.html">aes</a></span><span class="op">(</span>color <span class="op">=</span> <span class="va">role</span>, size <span class="op">=</span> <span class="va">`-log10(p)`</span><span class="op">)</span><span class="op">)</span>
<span class="va">p</span></code></pre></div>
<p><img src="surv-corr-connection_files/figure-html/unnamed-chunk-7-1.png" width="720" style="display: block; margin: auto;"></p>
<div class="sourceCode" id="cb8"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span class="va">p</span> <span class="op">+</span> 
  <span class="fu">ggnewscale</span><span class="fu">::</span><span class="fu"><a href="https://rdrr.io/pkg/ggnewscale/man/new_scale.html">new_scale</a></span><span class="op">(</span><span class="st">"color"</span><span class="op">)</span> <span class="op">+</span>
  <span class="fu"><a href="../reference/polar_connect.html">polar_connect</a></span><span class="op">(</span><span class="va">df_cor</span>, x1 <span class="op">=</span> <span class="va">var1</span>, x2<span class="op">=</span> <span class="va">var2</span>, size <span class="op">=</span> <span class="va">size</span>, color <span class="op">=</span> <span class="va">way</span>, alpha <span class="op">=</span> <span class="fl">0.3</span><span class="op">)</span> <span class="op">+</span> 
  <span class="fu"><a href="https://ggplot2.tidyverse.org/reference/scale_size.html">scale_size</a></span><span class="op">(</span>range <span class="op">=</span> <span class="fu"><a href="https://rdrr.io/r/base/c.html">c</a></span><span class="op">(</span><span class="fl">0.1</span>, <span class="fl">4</span><span class="op">)</span><span class="op">)</span>
<span class="co">#&gt; Scale for 'size' is already present. Adding another scale for 'size', which</span>
<span class="co">#&gt; will replace the existing scale.</span></code></pre></div>
<p><img src="surv-corr-connection_files/figure-html/unnamed-chunk-8-1.png" width="720" style="display: block; margin: auto;"></p>
</div>
  </div>

  <div class="col-md-3 hidden-xs hidden-sm" id="pkgdown-sidebar">

      </div>

</div>



      <footer><div class="copyright">
  <p>Developed by Shixiang Wang.</p>
</div>

<div class="pkgdown">
  <p>Site built with <a href="https://pkgdown.r-lib.org/">pkgdown</a> 1.6.1.</p>
</div>

      </footer>
</div>

  


  </body>
</html>
