R: Survminer 双图
R: Survminer double graph
我参与了一个项目,我们正在为一个发生率很低的事件绘制生存曲线,并且 Kaplan-Meier 曲线(使用 survminer
绘制)非常平坦。我不想简单地放大 Y 轴,因为我认为 reader 可能会误解发病率。一种既显示 'true' 比率又放大最终微小差异的方法是像 NEJM 那样做:
但是,我没有在 survminer
中找到直接执行此操作的方法。为了再现性,我想避免涉及任何 Adobe 软件。
有谁知道有什么方法可以在原始图表上添加一个放大的小版本吗?我想用 survminer
完成此操作,但对任何其他基于 ggplot 的 KM 软件包的提示表示赞赏。
小例子:
library(survival)
library(survminer)
df <- genfan
df$treat<-sample(c(0,1),nrow(df),replace=TRUE)
fit <- survfit(Surv(hours, status) ~ treat, data = df)
p <- ggsurvplot(fit, data = df, risk.table = TRUE, fun = 'event', ylim = c(0, 1))
p # Normal flat, singular graph
有几种方法可以做到这一点,但一个建议是制作您拥有的两个地块并用 grid.arrange
排列它们。首先制作两个图。然后提取风险 table 并为第一个图单独绘制(不能将 ggsurvplot 对象放在 grid.arrange
中)。用 annotation_custom 将第二个图嵌套在第一个图中。最后,使用 layout_matrix 指定绘图的尺寸并将其与 grid.arrange
放回一起。
library(survival)
library(survminer)
library(grid)
library(gridExtra)
df <- genfan
df$treat<-sample(c(0,1),nrow(df),replace=TRUE)
fit <- survfit(Surv(hours, status) ~ treat, data = df)
p <- ggsurvplot(fit, data = df, risk.table = TRUE, fun = 'event', ylim = c(0, 1))
#zoomed plot and remove risk table
g <- ggsurvplot(fit, data = df, risk.table = FALSE, fun = 'event', ylim = c(0, .5))
risktab <- p$table
justplot <- p$plot
p2 <- justplot +
annotation_custom(grob = ggplotGrob(g$plot+
theme(legend.position = "none")),
xmin = 60,xmax=Inf,ymin = .5,ymax = Inf)
lay <- rbind(c(1,1),
c(1,1),
c(2,2))
gridExtra::grid.arrange(p2, risktab,
#use layout matrix to set sizes
layout_matrix=lay
)
我参与了一个项目,我们正在为一个发生率很低的事件绘制生存曲线,并且 Kaplan-Meier 曲线(使用 survminer
绘制)非常平坦。我不想简单地放大 Y 轴,因为我认为 reader 可能会误解发病率。一种既显示 'true' 比率又放大最终微小差异的方法是像 NEJM 那样做:
但是,我没有在 survminer
中找到直接执行此操作的方法。为了再现性,我想避免涉及任何 Adobe 软件。
有谁知道有什么方法可以在原始图表上添加一个放大的小版本吗?我想用 survminer
完成此操作,但对任何其他基于 ggplot 的 KM 软件包的提示表示赞赏。
小例子:
library(survival)
library(survminer)
df <- genfan
df$treat<-sample(c(0,1),nrow(df),replace=TRUE)
fit <- survfit(Surv(hours, status) ~ treat, data = df)
p <- ggsurvplot(fit, data = df, risk.table = TRUE, fun = 'event', ylim = c(0, 1))
p # Normal flat, singular graph
有几种方法可以做到这一点,但一个建议是制作您拥有的两个地块并用 grid.arrange
排列它们。首先制作两个图。然后提取风险 table 并为第一个图单独绘制(不能将 ggsurvplot 对象放在 grid.arrange
中)。用 annotation_custom 将第二个图嵌套在第一个图中。最后,使用 layout_matrix 指定绘图的尺寸并将其与 grid.arrange
放回一起。
library(survival)
library(survminer)
library(grid)
library(gridExtra)
df <- genfan
df$treat<-sample(c(0,1),nrow(df),replace=TRUE)
fit <- survfit(Surv(hours, status) ~ treat, data = df)
p <- ggsurvplot(fit, data = df, risk.table = TRUE, fun = 'event', ylim = c(0, 1))
#zoomed plot and remove risk table
g <- ggsurvplot(fit, data = df, risk.table = FALSE, fun = 'event', ylim = c(0, .5))
risktab <- p$table
justplot <- p$plot
p2 <- justplot +
annotation_custom(grob = ggplotGrob(g$plot+
theme(legend.position = "none")),
xmin = 60,xmax=Inf,ymin = .5,ymax = Inf)
lay <- rbind(c(1,1),
c(1,1),
c(2,2))
gridExtra::grid.arrange(p2, risktab,
#use layout matrix to set sizes
layout_matrix=lay
)