1

我一直在尝试使用autoplotpackage 中的函数绘制生存函数survMisc。到目前为止它很好,情节很好,但问题是我不能使用scale_color_grey灰度。

代码是:

   autoplot(fit.bygroup, plotTable=TRUE, divideTime=1,legendLabs=c("group1", "group2"),  lty=c(1,2),geom_line(size=2))+ scale_color_grey()

我想问题是这autoplot是创建一个空白对象...有什么办法可以将它们更改为灰度颜色?或者如果我想要黑白背景怎么办?

    p<- autoplot(fit.bygroup, plotTable=TRUE, divideTime=1,legendLabs=c("group1", "group2"),  lty=c(1,2),geom_line(size=2))

这个p其实是NULL

4

2 回答 2

2

我认为您需要更改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)

在此处输入图像描述

于 2014-03-22T12:00:15.710 回答
0

从版本开始,0.4.2这有点不那么“hackey”了。 autoplot.survfit现在返回列表中的 atable和 a plot。在组合它们之前,可以根据需要进一步修改它们autoplot.tableAndPlot,如下所示:

data(kidney, package = "KMsurv")
s1 <- survfit(Surv(time = time, event = delta) ~ type, data = kidney)
library(survMisc)
tap1 <- autoplot(s1)
for (i in seq_along(tap1)){
    tap1[[i]] <- tap1[[i]] + scale_colour_grey(guide = guide_legend(keywidth = 3, keyheight = 3)) + theme_classic()
    }
autoplot(tap1)

给予:

在此处输入图像描述

或者单独修改情节,例如:

p1 <- autoplot(s1)$plot
p1 +
    scale_colour_grey(guide = guide_legend(keywidth = 3, keyheight = 3)) +
    theme_classic()
于 2014-05-20T20:43:08.603 回答