<p>In R software, I want to plot a graph by using cox regression with the restricted cubic spline method. However, I can't quite get it to work.</p>

<p>This is the code I'm using:</p>

<pre><code>library(rms); require(rms); library(Hmisc)
d&lt;-curve.men
dd &lt;- datadist(d)
options(datadist="dd")
fit &lt;- cph(Surv(time,death) ~ rcs(bmi,4)
           + systolic +glucose + l_chol + age 
           + edu_g2 + smoke_s + l_chol + drink + activity_l+activity_w,
             data=d, nk=5)
plot(Predict(fit,bmi), xlab="bmi", ylab="Relative Risk", lty=1, lwd=2)
</code></pre>

<p>Which creates the following plot <strong>(A)</strong>:</p>

<p><a href="https://i.sstatic.net/MoyLw.jpg" rel="nofollow noreferrer"><img src="https://i.sstatic.net/MoyLw.jpg" alt="enter image description here"></a></p>

<p>However, I want to plot the following graph <strong>(B)</strong>:</p>

<p><a href="https://i.sstatic.net/Fx5Qx.jpg" rel="nofollow noreferrer"><img src="https://i.sstatic.net/Fx5Qx.jpg" alt="enter image description here"></a></p>

<ol>
<li>How do I set the reference point? (for example: <code>bmi = 24.21429</code> as the reference point)</li>
<li>I want to add the horizontal line. I tried using <code>abline(h=1)</code>, but it did not work.</li>
<li>All in all, how do I make the graph look like (B)?</li>
</ol>

CC BY-SA 3.0
2016-01-13T08:25:40.240Z
in graph (A), y range is   -1.0 ~ 1.5,
Xudong Liu
CC BY-SA 3.0
2016-01-13T12:42:17.800Z
Welcome to Computer Graphics SE! I tried to improve the readability of your post a bit. However, I'm not sure it's a great fit for this site. You could probably just ask this on [so] instead. I've [started a discussion on meta](http://meta.computergraphics.stackexchange.com/q/205/16) whether questions about plotting simple graphs are considered on topic or not.
Martin Ender
CC BY-SA 3.0
2016-01-14T00:02:58.473Z
Given that this is specifically about R, it's likely a better fit for [Cross Validated](https://stats.stackexchange.com/).
Nathan Reed
CC BY-SA 4.0
2018-12-23T17:35:47.990Z
After discussion, the consensus seems to be that questions about plotting are off-topic. https://computergraphics.meta.stackexchange.com/questions/205/are-questions-about-plotting-graphs-on-topic
Julien Guertault
<line-drawing>
Problems in using cox regression with restricted cubic spline plot with R software
Xudong Liu
# Problems in using cox regression with restricted cubic spline plot with R software

(Asked by: username_0 on 2016-01-13)

In R software, I want to plot a graph by using cox regression with the restricted cubic spline method. However, I can't quite get it to work.

This is the code I'm using:

```
library(rms); require(rms); library(Hmisc)
d<-curve.men
dd <- datadist(d)
options(datadist="dd")
fit <- cph(Surv(time,death) ~ rcs(bmi,4)
           + systolic +glucose + l_chol + age 
           + edu_g2 + smoke_s + l_chol + drink + activity_l+activity_w,
             data=d, nk=5)
plot(Predict(fit,bmi), xlab="bmi", ylab="Relative Risk", lty=1, lwd=2)

```

Which creates the following plot **(A)**:

[![enter image description here](https://i.sstatic.net/MoyLw.jpg)](https://i.sstatic.net/MoyLw.jpg)

However, I want to plot the following graph **(B)**:

[![enter image description here](https://i.sstatic.net/Fx5Qx.jpg)](https://i.sstatic.net/Fx5Qx.jpg)

1. How do I set the reference point? (for example: `bmi = 24.21429` as the reference point)
2. I want to add the horizontal line. I tried using `abline(h=1)`, but it did not work.
3. All in all, how do I make the graph look like (B)?

**Tags:** line-drawing

> **Comments:**
> **username_0**: in graph (A), y range is   -1.0 ~ 1.5,  
> **username_1**: Welcome to Computer Graphics SE! I tried to improve the readability of your post a bit. However, I'm not sure it's a great fit for this site. You could probably just ask this on [so] instead. I've [started a discussion on meta](http://meta.computergraphics.stackexchange.com/q/205/16) whether questions about plotting simple graphs are considered on topic or not.  
> **username_2**: Given that this is specifically about R, it's likely a better fit for [Cross Validated](https://stats.stackexchange.com/).  
> **username_3**: After discussion, the consensus seems to be that questions about plotting are off-topic. https://computergraphics.meta.stackexchange.com/questions/205/are-questions-about-plotting-graphs-on-topic  

---

## 0 answers

