我想模仿《NEW ENGLAND JOURNAL OF MEDICINE》中生存图的风格。它经常在原比例图中嵌套一个带有放大y比例的生存图。就像这样。
我可以用survival和survminer R包来画一个没有风险的生存图,很容易。但是,我不知道如何将一个生存图与一个放大的y刻度嵌套在一起。
这是我试过的代码。
library("survival")
library("survminer")
library("ggplot2")
fit <- survfit(Surv(time,status) ~ sex, data = lung)
p1 <- ggsurvplot(fit, data = lung, pval = TRUE, fun = "pct",
risk.table = TRUE, size = 1,
tables.theme = theme_cleantable())
p2 <- ggsurvplot(fit, data = lung, pval = TRUE, fun = "pct", ylim=c(50, 100))
library(grid)
vp <- viewport(width =0.6, height = 0.6, x = 1,y = 1)
p1
print(p2,vp = vp)
但是,似乎视口功能不工作。
这种情况下,没有提供一个合适的例子,因为你的数据跨越从100到0%。然而这里有一个工作代码。
library("survival")
library("survminer")
library("ggplot2")
library("grid")
fit <- survfit(Surv(time,status) ~ sex, data = lung)
p1 <- ggsurvplot(fit, data = lung, pval = TRUE, fun = "pct",
risk.table = TRUE, size = 1,
legend = "none",
palette = c("#377eb8", "#e41a1c"),
tables.theme = theme_cleantable())
p2 <- p1$plot + coord_cartesian(ylim = c(50, 100)) + theme(legend.position = "none") + labs(x="", y="")
vp <- viewport(width = 0.3, height = 0.3, x = 1, y = 0.7, just = c("right","bottom"))
full <- function() {
print(p1)
theme_set(theme_classic())
print(p2, vp = vp)
}
full()