2
$\begingroup$

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

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

enter image description here

  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)?
$\endgroup$
  • $\begingroup$ in graph (A), y range is -1.0 ~ 1.5, $\endgroup$ – Xudong Liu Jan 13 '16 at 8:25
  • 3
    $\begingroup$ 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 Stack Overflow instead. I've started a discussion on meta whether questions about plotting simple graphs are considered on topic or not. $\endgroup$ – Martin Ender Jan 13 '16 at 12:42
  • 3
    $\begingroup$ Given that this is specifically about R, it's likely a better fit for Cross Validated. $\endgroup$ – Nathan Reed Jan 14 '16 at 0:02
  • 1
    $\begingroup$ After discussion, the consensus seems to be that questions about plotting are off-topic. computergraphics.meta.stackexchange.com/questions/205/… $\endgroup$ – Julien Guertault Dec 23 '18 at 17:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.