Convert pdf to png in R -
i'm trying convert pdf plot png or jpeg file. reason want use images presentations , need both formats, having same dimensions/scaling.
i tried function im.convert() in animation package, output looks bad, in both png , jpeg.
to able run following code need "animation" package , imagemagick software (http://www.imagemagick.org/script/convert.php)
library("animation") ani.options(outdir = getwd()) pdf("bm.pdf") plot(1:10) dev.off() im.convert("bm.pdf", output = "bm.jpeg") im.convert("bm.pdf", output = "bm.png")
the result of im.convert not satisfactory because uses default resolution, 74 dpi. can increase resolution passing parameter:
im.convert("bm.pdf", output = "bm.png", extra.opts="-density 150") -density 150 double resolution , pngs , jpegs nicer.
but in general better use png() , jpeg() generate plots , use appropiate parameters same results pdf(). example:
pdf(width=5, height=5) plot(1:10) dev.off() png(width=5, height=5, units="in", res=150) plot(1:10) dev.off()
Comments
Post a Comment