小编Gur*_*als的帖子

完美契合ggplot2绘图的情节

我想绘制一个受限制的三次样条曲线作为主图,并添加一个盒子和须状图来显示X变量的变化.然而,下铰链(x = 42),中间(x = 51)和上铰链(x = 61)与主曲线的相应网格线不完全吻合.

library(Hmisc)
library(rms)
library(ggplot2)
library(gridExtra)

data(pbc)
d <- pbc
rm(pbc)
d$status <- ifelse(d$status != 0, 1, 0)

dd = datadist(d)
options(datadist='dd')

f <- cph(Surv(time, status) ~  rcs(age, 4), data=d)
p <- Predict(f, fun=exp)
df <- data.frame(age=p$age, yhat=p$yhat, lower=p$lower, upper=p$upper)

### 1st PLOT: main plot
(g <- ggplot(data=df, aes(x=age, y=yhat)) + geom_line(size=1))

# CI
(g <- g + geom_ribbon(data=df, aes(ymin=lower, ymax=upper), alpha=0.5, linetype=0, fill='#FFC000'))

# white background
(g <- g + theme_bw())

# X-axis
(breaks …
Run Code Online (Sandbox Code Playgroud)

plot r spline ggplot2

6
推荐指数
1
解决办法
2202
查看次数

标签 统计

ggplot2 ×1

plot ×1

r ×1

spline ×1