【问题标题】:knitr: Saving graphs in both pdf and png format but using pdf files in the final documentknitr:以 pdf 和 png 格式保存图形,但在最终文档中使用 pdf 文件
【发布时间】:2015-02-25 01:16:01
【问题描述】:

使用dev = c("pdf", "png"),我可以创建pdfpng 格式的图表。我想知道如何强制knitr 在最终文档中使用pdf 格式图。我的以下 MWE 在最终文档中使用png 格式图表。我问a similar question before

\documentclass{article} 
\begin{document}
<<setup, include=FALSE, cache=FALSE>>=
opts_chunk$set(
                 fig.path   = 'figure/'
               , cache.path = 'cache/'
               , cache      = FALSE
               , dev        = c("pdf", "png")
               , fig.align  = 'center'
               , fig.show   = 'hold'
               , fig.width  = 8
               , fig.height = 6
               , out.width  = '.8\\linewidth'
               , par        = TRUE
               , echo       = FALSE
               , warning    = FALSE
               , message    = FALSE
               )
options(replace.assign = TRUE, width=80)
knit_hooks$set(par = function(before, options, envir){
if (before && options$fig.show!='none')
 par(
      mar=c(4, 4, 0.1, 0.1)
   , cex.lab = 0.95
   , cex.axis =0.9
   , mgp = c(2, 0.7, 0)
   , tcl = -0.3
   )
}, crop = hook_pdfcrop)
@


<< hist-test >>=
X <- rnorm(n=100, mean=0, sd=)
hist(x=X)
@ 

\end{document}

【问题讨论】:

    标签: r pdf plot png knitr


    【解决方案1】:

    简单,告诉 Latex 你的喜好,

    \DeclareGraphicsExtensions{%
        .pdf,.PDF,%
        .png,.PNG,%
        .jpg,.jpeg}
    

    【讨论】:

    猜你喜欢
    • 2012-03-28
    • 2018-10-18
    • 1970-01-01
    • 2021-12-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多