简体   繁体   中英

How can I merge two plots of restricted cubic spline using cox regression

I have produced two different plots based on two different models: fit1 and fit2. I want to attach the two plots, but I can not know how to do that.

df %>% filter(category_LVEF == 0) -> df1
df %>% filter(category_LVEF == 1) -> df2

install.packages("rms")
library(rms)
library(survival)
install.packages("datadist")

ddist1 <- datadist(df1)
options(datadist='ddist1')

fit1 <- cph(Surv(`time`, death) ~ rcs(heart rate, 4) + category_Age + category_BP + category_BUN + category_Na + copd, data = df1, nk = 5)
plot(Predict(fit1, heart rate), xlab = "heart rate", ylab = "Relative Risk", lty = 1, lwd = 2)
plot(Predict(fit1, heart rate, ref.zero = TRUE, fun = exp))

ddist2 <- datadist(df2)
options(datadist='ddist2')
fit2 <- cph(Surv(`time`, death) ~ rcs(heart rate, 4) + category_Age + category_BP + category_BUN + category_Na + copd, data = df2, nk = 5)
plot(Predict(fit2, heart rate), xlab = "heart rate", ylab = "Relative Risk", lty = 1, lwd = 2)
plot(Predict(fit2, heart rate, ref.zero = TRUE, fun = exp))

fit1

在此处输入图像描述

fit2

在此处输入图像描述

If you want tested code, then offer a version of df1. That said, the way to approach plotting problems for situations more complex than what the authors anticipated is to to first figure out what plotting paradigm is being used and then to see if there are additional parameters in base graphics like ylim and add=TRUE that will let you expand the range and overly graphic elements. If ggplot2 is the paradigm then obviously you will be using + and the appropriate additonal functions for those operations.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM