我用ggsurvplot绘制了一条Kaplan Meier曲线,如下所示:
kaplan_plot365d <- ggsurvplot(kmcurve365d,
conf.int = TRUE,
legend.labs = c('Trop-T normal and Trop-I normal', 'Trop-T elevated and Trop-I normal', "Trop-T elevated and Trop-I elevated"),
legend.title = '',
title = 'Kaplan-Meier Curve for 365-Day Mortality',
xlab = 'Time in Days',
ylab = 'Survival probability', main = 'Kaplan-Meier Model',
ylim=c(min(0.7), max(1)),
xlim=c(min(0), max(366)),
break.time.by = 120,
palette = c('#FDE725FF', "#21908CFF", "#440154FF"),
risk.table = TRUE,
risk.table.y.text = TRUE, fontsize = 4, tables.theme = clean_theme(),
risk.table.title = "Survivors per group") +
guides(colour = guide_legend(nrow = 2))
kaplan_plot365d
我想使整个背景透明,然后保存它与高品质使用它的海报。
我尝试在ggsurvplot()函数中添加以下代码行:但它不起作用
panel.background = element_rect(fill='transparent'), #transparent panel bg
plot.background = element_rect(fill='transparent', color=NA), #transparent plot bg
panel.grid.major = element_blank(), #remove major gridlines
panel.grid.minor = element_blank(), #remove minor gridlines
legend.background = element_rect(fill='transparent'), #transparent legend bg
legend.box.background = element_rect(fill='transparent') #transparent legend panel
然后我使用下面的代码来保存它:
grid.draw.ggsurvplot <- function(x){
survminer:::print.ggsurvplot(x, newpage = FALSE)}
ggsave("Kaplan-Meier_365d_withCI_Troponine.jpg",
path = ("I:\\Personal\\Poster/"),
plot = kaplan_plot365d,
dpi = 300)
有人能帮我把背景变透明吗?
谢谢大家!
1条答案
按热度按时间qqrboqgw1#
我想我已经知道它是如何工作的了,也知道了确保它与
ggsave
、grid.draw
和ggsurvplot
结合在一起的复杂性。关键是,这些行位于ggsurvplot
函数的ggtheme = theme(...)
调用中:然后保存为png以给予透明图像:
结果是: