【问题标题】:How can I merge two plots of restricted cubic spline using cox regression如何使用 cox 回归合并两个受限三次样条图
【发布时间】:2020-12-10 01:57:15
【问题描述】:

我根据两个不同的模型制作了两个不同的图:fit1 和 fit2。我想附上这两个图,但我不知道该怎么做。

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))

适合1

适合2

【问题讨论】:

  • 你想怎么附加它们?
  • 如果附加您的意思是叠加,您需要par他们。如果您打算将它们放在一个图中(在不同的行/列中),您将需要ggarrange 他们。详细说明问题,我可以添加一个很好的示例 =)

标签: r cubic-spline


【解决方案1】:

如果您需要经过测试的代码,请提供 df1 版本。也就是说,解决比作者预期更复杂的情况的绘图问题的方法是首先弄清楚正在使用什么绘图范例,然后查看基本图形中是否有其他参数,如ylimadd=TRUE这将使您扩大范围和过度的图形元素。如果 ggplot2 是范例,那么显然您将使用 + 和这些操作的适当附加函数。

【讨论】:

    猜你喜欢
    • 2022-07-29
    • 1970-01-01
    • 1970-01-01
    • 2017-05-07
    • 1970-01-01
    • 2015-05-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多