writing png plots into a pdf file in R

后端 未结 3 1164
青春惊慌失措
青春惊慌失措 2021-01-04 06:05

I have to create a bunch of graphs with a lot of data points. So far, I\'ve been doing this by plotting all of them into one pdf-file:

pdf(\"tes         


        
相关标签:
3条回答
  • 2021-01-04 06:41

    You can convert the PNG files to PDF with ImageMagick

    for i in *.png
    do
      convert "$i" "$i".pdf
    done
    

    and concatenate the resulting files with pdftk.

    pdftk *.png.pdf output all.pdf
    
    0 讨论(0)
  • 2021-01-04 06:43

    If the source of the problem is too many points in the plot then you might want to consider using hexagonal binning instead of a regular scatterplot. You can use the hexbin package from bioconductor or the ggplot2 package has hexagonal binning capabilities as well. Either way you will probably get a more meaningful plot as well as smaller file size when creating a pdf file directly.

    0 讨论(0)
  • 2021-01-04 06:55

    You can

    1. create .png files of each plot
    2. use the png package to read those back in and
    3. plot them in a pdf using grid.arrange
    library(png)
    library(grid)
    library(gridExtra)
    
    thePlots <- lapply (2:length(names(mtcars)), function(i) {
      png("testgraph.png")
      plot(mtcars[,1], mtcars[,i])
    
      dev.off()
      rasterGrob(readPNG("testgraph.png", native = FALSE),
        interpolate = FALSE)
    })
    
    pdf("testgraph.pdf")
    do.call(grid.arrange, c(thePlots, ncol = 3))
    dev.off()
    
    0 讨论(0)
提交回复
热议问题