R icenReg 包:移动图例 ic_np 适合
R icenReg package: Move plot legend for ic_np fit
我需要创建一个图来比较三个物种的区间截尾生存曲线。我能够使用 R 中 icenReg
包中的 ic_np
函数生成显示所有三个曲线的图。当我使用 base R [=15 绘制此 ic_np
拟合的输出时=],左下角出现图例。
这个来自 icenReg
包文档的例子产生了一个类似的数字:
library(icenReg)
data(miceData)
fit <- ic_np(cbind(l, u) ~ grp, data = miceData) #Stratifies fit by group
plot(fit)
但是,左下角的标题涵盖了我最有趣的生存曲线比较,所以我想将图例移到右上角。
我已经看到 this question 关于在 base R 中为基本图设置图例位置。这个问题的答案似乎假设我可以生成没有图例的图,但我无法做到那。
我还看到 this question 关于将图例添加到其他类型的生存分析中,这些生存分析似乎默认情况下不会生成图例,但我无法使用区间截尾数据实现这些方法。
我了解到我无法移动已经添加到绘图中的图例,但我不知道如何在没有图例的情况下生成此特定绘图这样我就可以在我想要的地方添加一个(右上角)。
我怎样才能 (a) 使用没有图例的 ic_np
生成这个区间截尾 Kaplan-Meier 生存曲线图——也许使用 plot()
的一些隐藏参数——或者(b) 使用不同的绘图设备生成此图,假设绘图图例可以移动?
包中似乎没有plot函数的帮助页面所以你需要确定fit
对象的class并查看代码:
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")
我需要创建一个图来比较三个物种的区间截尾生存曲线。我能够使用 R 中 icenReg
包中的 ic_np
函数生成显示所有三个曲线的图。当我使用 base R [=15 绘制此 ic_np
拟合的输出时=],左下角出现图例。
这个来自 icenReg
包文档的例子产生了一个类似的数字:
library(icenReg)
data(miceData)
fit <- ic_np(cbind(l, u) ~ grp, data = miceData) #Stratifies fit by group
plot(fit)
但是,左下角的标题涵盖了我最有趣的生存曲线比较,所以我想将图例移到右上角。
我已经看到 this question 关于在 base R 中为基本图设置图例位置。这个问题的答案似乎假设我可以生成没有图例的图,但我无法做到那。
我还看到 this question 关于将图例添加到其他类型的生存分析中,这些生存分析似乎默认情况下不会生成图例,但我无法使用区间截尾数据实现这些方法。
我了解到我无法移动已经添加到绘图中的图例,但我不知道如何在没有图例的情况下生成此特定绘图这样我就可以在我想要的地方添加一个(右上角)。
我怎样才能 (a) 使用没有图例的 ic_np
生成这个区间截尾 Kaplan-Meier 生存曲线图——也许使用 plot()
的一些隐藏参数——或者(b) 使用不同的绘图设备生成此图,假设绘图图例可以移动?
包中似乎没有plot函数的帮助页面所以你需要确定fit
对象的class并查看代码:
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")