首先您需要查看代码。
ggadjustedcurves
看起来ggadjustedcurves
将所有参数传递给依赖于“方法”参数的辅助函数,在本例中为“平均”,所以现在看看那个(隐藏)函数:
getAnywhere( ggadjustedcurves.average )
请注意,除了“主函数”中定义的少数参数外,没有规定接受其他参数,即不使用 R 的省略机制或除大小之外的其他可能的 aes 参数的规范。 (它也没有使用geom_line
.)所以你需要改变both主函数and辅助函数接受“linetype”参数。这里我展示了如何修改辅助函数(尽管这需要对ggadjustedcurves
函数以及其他辅助函数(如果您希望这是完全通用的):
assignInNamespace('ggadjustedcurves.average',
function (data, fit, variable, size = 1, ..., linetype=linetype)
{
time <- surv <- NULL
lev <- sort(unique(data[, variable]))
pred <- survexp(as.formula(paste("~", variable)), data = data,
ratetable = fit)
curve <- data.frame(time = rep(c(0, pred$time), length(lev)),
variable = factor(rep(lev, each = 1 + length(pred$time))),
surv = c(rbind(1, pred$surv)))
ggplot(curve, aes(x = time, y = surv, color = variable)) +
geom_step(size = size, ..., linetype=linetype) # not geom_line
},
pos="package:survminer")
如果您对“geom_segment linetype”进行SO搜索,您会发现geom_segment
(这是什么geon_step
使用)的构造方式并不容易给它短向量来修改阶跃函数结果的“连续”长度。看使用线型和组美学的ggplot错误 https://stackoverflow.com/questions/27005299/ggplot-error-using-linetype-and-group-aesthetics。这意味着您需要使用for-loop
or lapply
如果您需要不同的线型,可以构建单独的“阶梯曲线”。