Making flattened pdfs in Sweave

前端 未结 3 1029
北荒
北荒 2021-01-06 17:45

So I am creating pdfs using Sweave that include some graphs that have a ton of points on them. I can get the pdf well enough, but it seems to have created it with a ton of l

3条回答
  •  离开以前
    2021-01-06 17:50

    As Gavin said, there is no need to switch to knitr for this, though there are other advantages to do so. However, you don't even need to write your own saving and including code; Sweave can do that for you. If the initial document is:

    \documentclass{article}
    \usepackage[american]{babel}
    \begin{document}
    
    <<>>=
    n <- 100000
    DF <- data.frame(x=rnorm(n), y=rnorm(n))
    @
    
    <>=
    plot(DF)
    @
    
    \end{document}
    

    Then just by changing the arguments to the figure chunk, you can get a PNG instead of a PDF:

    <>=
    plot(DF)
    @
    

    In this simple example, it shrinks my final PDF from 685K to 70K.

提交回复
热议问题