【问题标题】:Modifying graphs in 'survrec' package修改“survrec”包中的图形
【发布时间】:2015-10-25 13:49:35
【问题描述】:

我是 R 新手,我正在使用包“survrec”。我想修改具有多个组的图形中的颜色和线条。该软件包包括以下示例:

data(colon)
# fit a pena-strawderman-hollander and plot it
fit<-survfitr(Survr(hc,time,event)~as.factor(dukes),data=colon,type="pena")
plot(fit,ylim=c(0,1),xlim=c(0,2000))

像在其他图表或“survfit”对象中那样使用参数“col”或“lty”不起作用。

plot(fit,ylim=c(0,1),xlim=c(0,2000), col=c("red", "blue", "orange"), lty=3)

【问题讨论】:

    标签: r survival-analysis


    【解决方案1】:

    使用palette 影响基本图的调色板,使用par 修改其他参数默认值:

    library(survrec)
    library(viridis)
    
    data(colon)
    fit<-survfitr(Survr(hc,time,event)~as.factor(dukes),data=colon,type="pena")
    
    palette(viridis(3))
    plot(fit,ylim=c(0,1),xlim=c(0,2000))
    

    palette(c("#7f3b08", "#2d004b", "#1b7837"))
    plot(fit,ylim=c(0,1),xlim=c(0,2000))
    

    palette(c("red", "blue", "orange"))
    par(lty=3)
    plot(fit,ylim=c(0,1),xlim=c(0,2000))
    

    不幸的是survrec:::plot.survfitr 硬编码lty=2 用于上/下行。如果需要,您可以复制该函数并将其参数化。

    【讨论】:

    • 非常感谢!这很有帮助!
    • PS:有没有办法为每个组设置不同的线型?
    • 您必须编辑函数以进行该级别的自定义或将基础数据转换为数据框并使用 ggplot2。在github.com/sinhrks/ggfortify 中有一些后者的例子
    猜你喜欢
    • 2019-06-19
    • 2016-01-13
    • 1970-01-01
    • 2019-02-19
    • 1970-01-01
    • 1970-01-01
    • 2020-07-17
    • 1970-01-01
    • 2016-09-24
    相关资源
    最近更新 更多