简体   繁体   English

R icenReg包:移动ic_np fit的图例

[英]R icenReg package: Move plot legend for ic_np fit

I need to create a plot that compares interval censored survival curves for three species. 我需要创建一个比较三种物种的区间删失生存曲线的图。 I am able to generate a plot that shows all three curves using the ic_np function in the icenReg package in R. When I plot the output of this ic_np fit using base R plot() , a legend appears in the bottom left corner. 我能够使用ic_npicenReg包中的ic_np函数生成显示所有三条曲线的图。当我使用基本R plot()ic_np拟合的输出时, ic_np出现一个图例。

This example from the icenReg package documentation yields a similar figure: 来自icenReg包文档的这个例子产生了一个类似的数字:

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

However, having the caption in the bottom left covers the most interesting comparison of my survival curves, so I would like to move the legend to the top right. 但是,左下方的标题涵盖了我生存曲线最有趣的比较,所以我想将图例移到右上角。

I have seen this question about setting a legend position for basic plots in base R. Answers to this question seem to assume that I can generate a plot without the legend, but I have not been able to do that. 我已经看到了这个问题,有关设置图例位置为基础R.这个问题的答案基本情节似乎认为我才能不用传说情节,但我一直没能做到这一点。

I have also seen this question about adding a legend to other types of survival analysis that do not seem to generate a legend by default, but I have not been able to implement these methods with interval censored data. 我还看到了这个问题,即将图例添加到其他类型的生存分析中,默认情况下似乎没有生成图例,但我无法使用区间删失数据实现这些方法。

I have read that I can't move a legend that has already been added to a plot, but I don't know how to generate this particular plot without a legend so that I can add one back in where I want it (top right). 我已经读过,我无法移动已添加到绘图中的图例,但我不知道如何在没有图例的情况下生成此特定图以便我可以在我想要的位置添加一个(右上角) )。

How can I either (a) generate this plot of interval censored Kaplan-Meier survival curves using ic_np without a legend -- maybe using some hidden parameter of plot() -- OR (b) generate this figure using a different plotting device, assuming the plot legend is then moveable? 我怎样才能(a)使用没有图例的ic_np生成间隔删除的Kaplan-Meier生存曲线图 - 可能使用一些隐藏的plot()参数 - 或者(b)使用不同的绘图设备生成此图,假设情节传说是可移动的吗?

There doesn't seem to be a help page in the package for the plot function so you need to determine the class of the fit -object and look at the code: 在绘图函数的包中似乎没有帮助页面,因此您需要确定fit -object的类并查看代码:

class(fit)
#[1] "ic_npList"
#attr(,"package")
#[1] "icenReg"

 plot.ic_npList
#Error: object 'plot.ic_npList' not found

So it's not exported and we need to dig deeper (not suprising since exported functions do need to have help pages.) 因此它不会被导出,我们需要深入挖掘(不要太惊讶,因为导出的函数需要有帮助页面。)

 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>

So there is a location parameter for the legend placement and the obvious alternative to try is: 因此,图例展示位置有一个位置参数,而尝试的明显替代方法是:

plot(fit, lgdLocation = "topright")

在此输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM