简体   繁体   English

Survminer 的生存图 - 空白图

[英]Survival Plots with Survminer - Blank Plot

I'm currently having an issue with blank plots appearing in rmarkdown chunk outputs for survminer.我目前在 survminer 的 rmarkdown 块输出中出现空白图的问题。 Please see image below.请看下图。

在此处输入图片说明

It makes output difficult as it includes a huge empty space while trying to author reports.它使输出变得困难,因为它在尝试编写报告时包含巨大的空白空间。

在此处输入图片说明

I've been investigating this issue and I've narrowed it down to having to do with this print 'newpage' argument -我一直在调查这个问题,并将其范围缩小到与这个打印“新页”的论点有关 -

在此处输入图片说明

My question is - can anybody explain what exactly is happening here?我的问题是 - 谁能解释一下这里到底发生了什么? - why is there a 'blank' plot and how can I not have it show ? - 为什么有一个“空白”的情节,我怎么能不显示它? - what exactly is happening when I have newpage = F for the first plot and newpage = T for the second plot to not have the blank page show ? - 当我有第一个情节的 newpage = F 和第二个情节的 newpage = T 没有空白页显示时,究竟发生了什么? - is there any other method of NOT having the first blank plot show ? - 有没有其他方法可以不显示第一个空白图?

Thank you!谢谢!

EDIT:编辑:

Reproducible Example -可重现的例子 -

require(survminer)
require(survival)

Data <- data.frame(
X = sample(1:30),
Y = sample(c(1,0), 30, replace = TRUE),
Z = sample(c(1,0), 30, replace = TRUE)
)

ggsurvplot(
 survfit(Surv(Data$X, Data$Y) ~ Data$Z),
 risk.table = T,
 break.time.by = 12,
 risk.table.fontsize = 3,
 font.tickslab = 10,
 font.x = 11,
 xlab = 'Time (Months)',
 font.y = 11,
 font.main = 11,
 legend = c(0.8, .9),
 legend.title = '',
 risk.table.height = .20,
 risk.table.title = element_blank(),
 censor = F,
 pval = T,
 pval.coord = c(6, .00),
 pval.size = 4,
 surv.scale = 'percent',
 risk.table.y.text = F,
 palette = 'Set1'
)

In order to print the survival plot with no leading blank plots, print just the plot object returned by ggsurvplot() .为了打印没有前导空白图的生存图,只需打印ggsurvplot()返回的plot对象。 For example,例如,

library(survival)
library(survminer)
fit <- survfit(Surv(time, status) ~ sex, data = lung)
p <- ggsurvplot(fit, data = lung)
print(p$plot)

This seems to work for me :这似乎对我有用:

plot.new() 
print(p,newpage = FALSE)

This will also work if the plot has the risk table.如果情节有风险表,这也将起作用。 This solution is better than doing first plot(p$plot) and then plot(p$table) as suggested by others, because the table and plots remain nicely aligned.该解决方案比其他人建议的先执行plot(p$plot)然后执行plot(p$table)更好,因为表格和绘图保持良好对齐。

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

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