如何在R中保存使用forestplot包创建的绘图



我使用R中的forestplot包创建了一个林图,如下所示:

own <- fpTxtGp(ticks = gpar(cex = 0.65), xlab = gpar(fontsize = 16))
xticks <- seq(from = -0.25, to = 1, by = 0.25)
fn <- local({
i = 0
no_lines <- sum(!is.na(forest$mean))
b_clrs = colorRampPalette(colors=c("#21538A", "#21538A", "#A2B6D3", "#A2B6D3", "#DAE0EC"))(no_lines)
function(..., clr.marker){
i <<- i + 1
fpDrawCircleCI(..., clr.marker = b_clrs[i])
}
})
fplot <- forestplot::forestplot(text, 
fn.ci_norm = fn,
lower = forest$low, 
upper = forest$high, 
mean = forest$mean, 
is.summary = c(TRUE, FALSE, FALSE, TRUE, FALSE, FALSE, TRUE),
xlab = "SPI-CY risk score difference (SD)",
col = fpColors(line = "darkgrey", summary = "#DAE0EC", zero = "black"), 
vertices = TRUE, 
grid = TRUE,
boxsize = .35,
txt_gp = own,
xticks = xticks,
lwd.zero = 1.25
) 

我想直接从我的R笔记本中保存绘图。我通常用ggsave保存图,但林图是一个网格对象,所以这不起作用:

ggsave("forestplot.png", height = 5, width = 7, dpi = 600)

我试着用pdf((保存它,但这也不能直接从我的笔记本上运行。欢迎提出任何建议。

要直接从R笔记本中保存绘图(由于用户2554330的评论,我添加了绘图初始化(:

# initialize plot
png("forestplot.png", width=480, height=480)
# make plot
fplot
# save plot
dev.copy(png, "forestplot.png")
dev.off()

相关内容

  • 没有找到相关文章

最新更新