我认为您需要更改autoplot
. 您可以在此处survMisc
找到有关如何查看源代码的非常好的帖子。
输入autoplot
控制台。
autoplot
# ...snip
# UseMethod("autoplot")
# ...snip
UseMethod("autoplot")
意味着这autoplot
是一种S3
方法。然后我们可以methods
用来列出可用的方法。
methods(autoplot)
# [1] autoplot.default* autoplot.survfit autoplot.zoo
输入autoplot.survfit
控制台。
autoplot.survfit
将代码复制到编辑器。
更改色阶:
搜索“scale_col”,您将找到以下三个实例:
scale_colour_brewer(type = "qual", palette = "Dark2",
guide = guide_legend(keywidth = 3, keyheight = 3))
将它们替换为:
scale_colour_grey(guide = guide_legend(keywidth = 3, keyheight = 3))
更改背景颜色
在倒数第二个代码部分:
替换print(g1)
为(或您喜欢的print(g1 + theme_classic())
任何其他)
替换为,theme
grid.arrange(arrangeGrob(g1 + theme(legend.position = "none"),
grid.arrange(arrangeGrob(g1 + theme_classic() + theme(legend.position = "none")
使用新名称保存更新后的函数,例如autoplot.survfit2
.
在第一个示例中尝试?survMisc::autoplot
data(kidney, package = "KMsurv")
s1 <- survfit(Surv(time = time, event = delta) ~ type, data = kidney)
autoplot.survfit2(s1)
