首页 文章

R icenReg包:移动ic_np fit的图例

提问于
浏览
3

我需要创建一个比较三种物种的区间删失生存曲线的图 . 我能够使用R中 icenReg 包中的 ic_np 函数生成显示所有三条曲线的图 . 当我使用基础R plot() 绘制此 ic_np 拟合的输出时,左下角会出现一个图例 .

icenReg 包文档中的这个示例产生了类似的数字:

library(icenReg)
data(miceData)
fit <- ic_np(cbind(l, u) ~ grp, data = miceData) #Stratifies fit by group
plot(fit)

但是,左下方的 Headers 涵盖了我生存曲线最有趣的比较,所以我想将图例移到右上角 .

我已经看过this question关于为基础R中的基本图设置图例位置 . 这个问题的答案似乎假设我可以生成没有图例的情节,但我无法做到这一点 .

我还看到this question关于向其他类型的生存分析添加一个图例,默认情况下似乎没有生成图例,但我无法使用区间删失数据实现这些方法 .

我已经读过,我可以知道如何生成这个特殊的情节 without 一个传奇,这样我就可以在我需要的地方添加一个(右上角) .

我怎样才能(a)使用没有图例的 ic_np 生成区间删失的Kaplan-Meier生存曲线图 - 可能使用 plot() 的一些隐藏参数 - 或者(b)使用不同的绘图设备生成此图,假设情节传说是可移动的?

1 回答

  • 3

    在绘图函数的包中似乎没有帮助页面,因此您需要确定 fit -object的类并查看代码:

    class(fit)
    #[1] "ic_npList"
    #attr(,"package")
    #[1] "icenReg"
    
     plot.ic_npList
    #Error: object 'plot.ic_npList' not found
    

    因此它不会被导出,我们需要深入挖掘(不要太惊讶,因为导出的函数需要有帮助页面 . )

    getAnywhere(plot.ic_npList)
    #-----------
    A single object matching ‘plot.ic_npList’ was found
    It was found in the following places
      registered S3 method for plot from namespace icenReg
      namespace:icenReg
    with value
    
    function (x, fitNames = NULL, lgdLocation = "bottomleft", ...) 
    {
        addList <- list(xlim = x$xRange, ylim = c(0, 1), xlab = "time", 
            ylab = "S(t)", x = NA)
        dotList <- list(...)
       #.........
    #..........
        legend(lgdLocation, legend = grpNames, col = cols, lty = 1)
    }
    <bytecode: 0x7fc9784fa660>
    <environment: namespace:icenReg>
    

    因此,图例展示位置有一个位置参数,而尝试的明显替代方法是:

    plot(fit, lgdLocation = "topright")
    

    enter image description here

相关问题