title: Plotting a Cox PH model using ggforest in RStudio when a factor is stratified?
body: <p>I am trying to find a way to make a forest plot of hazard ratios from a Cox-PH model when one of the model variables needs to be stratified. For a non-stratified model, the <code>ggforest()</code> function is excellent. Running some example code</p>
  <pre><code>library(survival)
  library(survminer)
  
  model &lt;- coxph(Surv(time, status) ~ sex + rx + adhere,
                 data = colon )
  ggforest(model)
  
  colon &lt;- within(colon, {
    sex &lt;- factor(sex, labels = c(&quot;female&quot;, &quot;male&quot;))
    differ &lt;- factor(differ, labels = c(&quot;well&quot;, &quot;moderate&quot;, &quot;poor&quot;))
    extent &lt;- factor(extent, labels = c(&quot;submuc.&quot;, &quot;muscle&quot;, &quot;serosa&quot;, &quot;contig.&quot;))
  })
  bigmodel &lt;-
    coxph(Surv(time, status) ~ sex + rx + adhere + differ + extent + node4,
          data = colon )
  ggforest(bigmodel)
  </code></pre>
  <p>produces this graph</p>
  <p><img src="https://i.stack.imgur.com/C9N6M.png" alt="non-stratified figure" /></p>
  <p>However if I have to correct for non-proportionality with stratification</p>
  <pre><code>stratamodel &lt;- coxph(Surv(time, status) ~ sex + strata(rx) + adhere + differ + extent + node4,
                       data = colon )
  ggforest(stratamodel)
  </code></pre>
  <p>The following error message appears:</p>
  <blockquote>
  <p>&quot;Error in <code>[.data.frame</code>(data, , var) : undefined columns selected</p>
  </blockquote>
  <p>In addition: Warning message:</p>
  <blockquote>
  <p>In .get_data(model, data = data) :   The <code>data</code> argument is not
  provided. Data will be extracted from model fit.&quot;</p>
  </blockquote>
  <p>Any suggestions for how to get the information that ggforest needs from the strata model so that it can produce a plot? Thanks for your help!</p>