在pdf中组合矢量和位图图形

Bac*_*lin 4 r

当将图像或热图绘制到pdf时,如下例所示,它们被保存为矢量对象,其中热图中图像或单元格中的每个像素都用正方形表示.即使在适度的分辨率下,这也会导致不必要的大文件,这些文件也会在某些设备上呈现丑陋.有没有办法让R只将图像区域保存为嵌入在pdf中的png或jpg,但保留文本,轴,anotations等作为矢量图形?

我问,因为我经常打印R图形,有时在大型海报上,并希望结合两个世界中最好的.当然,我可以将整个数字保存为高分辨率png,但不会那么优雅,或者手动组合,例如在Inkscape中,但它非常繁琐.

my.func <- function(x, y) x %*% t(y)
pdf(file="myPlot.pdf")
image(my.func(seq(-10,10,,500), seq(-5,15,,500)), col=heat.colors(100))
dev.off()
Run Code Online (Sandbox Code Playgroud)

上面代码生成的数字

感谢您的时间,想法和希望解决方案!

mds*_*ner 10

使用?rasterImage,或在更新版本中image使用选项更方便useRaster = TRUE.

这将大大减少文件的大小.

my.func <- function(x, y) x %*% t(y)
pdf(file="image.pdf")
image(my.func(seq(-10,10,,500), seq(-5,15,,500)), col=heat.colors(100))
dev.off()

pdf(file="rasterImage.pdf")
image(my.func(seq(-10,10,,500), seq(-5,15,,500)), col=heat.colors(100), useRaster = TRUE)
dev.off()

file.info("image.pdf")$size

file.info("rasterImage.pdf")$size
Run Code Online (Sandbox Code Playgroud)

image.pdf:813229字节

rasterImage.pdf 16511个字节

在此处查看有关新功能的更多详细信息:

http://developer.r-project.org/Raster/raster-RFC.html

http://journal.r-project.org/archive/2011-1/RJournal_2011-1_Murrell.pdf