【发布时间】:2021-12-29 15:55:05
【问题描述】:
我一直在尝试将 flextable 保存为 ggplot,然后将其写入 PNG 进行网格化。我已经得到了我需要的东西,除了生成的 PNG 的背景是灰色的,像这样:
而 ggplot 的绘图视图看起来像我想要的(但分辨率低):
这是我用来生成图像的代码(flexRPOPS 是一个 flextable 对象):
library(flextable); library(ggplot2); library(png); library(magick);library(webshot)
flexRPOPS_raster <- as_raster(flexRPOPS, zoom = 20, webshot="webshot")
flexRPOPS_raster <- image_trim(flexRPOPS_raster, fuzz = 10)
flexRPOPS_ggplotex <- ggplot() + annotation_custom(rasterGrob(flexRPOPS_raster), xmin=-Inf, xmax=Inf, ymin=-Inf, ymax=Inf)
flexRPOPS_compare_ex1 <- ggsave(filename = "deptovr_ex1.png", flexRPOPS_ggplotex, width = flexRPOPS_dims$widths, height = flexRPOPS_dims$heights, dpi = 600, units = "in", bg="#ffffff", device='png')
【问题讨论】: