使用灰度自动绘图(survMisc)绘制生存图

使用灰度自动绘图(survMisc)绘制生存图,r,plot,survival-analysis,R,Plot,Survival Analysis,我一直在尝试使用packagesurvMisc中的autoplot函数绘制生存函数。到目前为止,它是好的,绘图是好的,但问题是我不能使用scale\u color\u grey来使用灰色色阶 代码是: autoplot(fit.bygroup, plotTable=TRUE, divideTime=1,legendLabs=c("group1", "group2"), lty=c(1,2),geom_line(size=2))+ scale_color_grey() 我想问题是这个au

我一直在尝试使用package
survMisc
中的
autoplot
函数绘制生存函数。到目前为止,它是好的,绘图是好的,但问题是我不能使用
scale\u color\u 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我认为您需要更改
survMisc
使用的
autoplot
功能的代码。你会发现一篇关于如何查看源代码的非常好的帖子

在控制台中键入
autoplot

autoplot
# ...snip
# UseMethod("autoplot")
# ...snip
autoplot.survfit
usethod(“autoplot”)
表示
autoplot
是一种
S3
方法。然后我们可以使用
方法
列出可用的方法

methods(autoplot)
# [1] autoplot.default* autoplot.survfit  autoplot.zoo
在控制台中键入
autoplot.survfit

autoplot
# ...snip
# UseMethod("autoplot")
# ...snip
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\u classic())
(或您喜欢的任何其他
主题)
grid.arrange(arrangeGrob(g1+theme)(legend.position=“none”),
替换为
grid.arrange(arrangeGrob(g1+theme\u 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)
数据(肾脏,包装=“KMsurv”)

s1从版本
0.4.2
开始,这就少了一点“黑客”。
autoplot.survfit
现在返回列表中的
表格和
绘图。
在使用
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)
数据(肾脏,包装=“KMsurv”)

s1是的,谢谢最后我实际使用了普通绘图功能。但我认为你的答案是完美的。是的!我确实是Stackoverflow的新手,但非常感谢你,这真的很有帮助,很高兴能提供服务。是的,非常感谢你,我试图更改源代码……它工作正常,但我认为还有一些其他问题需要解决解决,但非常感谢。