0

我使用 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() 保存它,但这也不能直接从我的笔记本上工作。欢迎任何建议。

4

1 回答 1

0

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

# initialize plot
png("forestplot.png", width=480, height=480)

# make plot
fplot

# save plot
dev.copy(png, "forestplot.png")
dev.off()
于 2018-12-04T16:47:09.023 回答