Plot as bitmap in PDF

前端 未结 4 1773
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-17 02:08

I am currently working on CGH array results, which involve several plots of dozens of thousands of points, and i would like to benefit from the multiple page feature of the

4条回答
  •  悲&欢浪女
    2020-12-17 02:21

    Here's a solution that gets you close (50kb) to your desired file size (25kb), without requiring you to install LaTeX and/or learn Sweave. (Not that either of those are undesirable in the long-run!)

    It uses the grid functions grid.cap() and grid.raster(). More details and ideas are in a recent R-Journal article by Paul Murrell (warning : PDF):

    require(grid)
    # Make the plots
    dev.new()  # Reducing width and height of this device will produce smaller raster files
        plot(rnorm(2e4), rnorm(2e4), pch="+", cex=0.6)
        cap1 <- grid.cap()
        plot(rnorm(2e4), rnorm(2e4), pch="+", cex=0.6, col="red")
        cap2 <- grid.cap()
    dev.off()
    
    # Write them to a pdf
    pdf("test.pdf", onefile=TRUE)
         grid.raster(cap1)
         plot.new()
         grid.raster(cap2)
    dev.off()
    

    The resulting pdf images appear to retain more detail than your files test1.png and test2.png, so you could get even closer to your goal by trimming down their resolution.

提交回复
热议问题