draw_image()
使用cowplot中的函数读取矢量化pdf 有时会导致图像严重模糊:
library(ggplot2)
library(cowplot)
library(magick)
# make pdf input as example
p <- ggplot(iris, aes(Sepal.Length, Sepal.Width, shape = Species)) +
geom_point() + scale_shape_manual(values = 21:23) + theme_classic()
ggsave("input.pdf", p, width = 6, height = 4.2)
# now draw with draw_image() and then write as png
fig <- ggdraw() + draw_image("input.pdf")
ggsave("output.png", fig, width = 1, height = .7, dpi = 1200) # blurred image
但是,阅读 SVG 可以正常工作:
fig <- ggdraw() +
draw_image("http://jeroen.github.io/images/tiger.svg")
ggsave("output.png", fig, width = 1, height = .7, dpi = 1200)
此外,使用:
magick::image_read_pdf("input.pdf")
导致输出不模糊。