Poor resolution in knitr using Rmd

后端 未结 3 1067
你的背包
你的背包 2020-12-29 02:30

I have a .Rmd file and I am trying to create a .docx file via the function pandoc.

I want to have a figure with final resolution of 504x504 pixels (i.e., 7x7inch wi

3条回答
  •  别那么骄傲
    2020-12-29 02:59

    This is a great time to take advantage of knitr's built-in dynamic customization features for output types. Ths was tested with both output targets...

    ````{r img-setup, include=FALSE, cache=FALSE}
    out.format <- knitr::opts_knit$get("out.format")
    img_template <- switch( out.format,
                         word = list("img-params"=list(fig.width=6,
                                                       fig.height=6,
                                                       dpi=150)),
                         {
                           # default
                           list("img-params"=list( dpi=150,
                                                   fig.width=6,
                                                   fig.height=6,
                                                   out.width="504px",
                                                   out.height="504px"))
                         } )
    
    knitr::opts_template$set( img_template )
    ````
    

    If you don't want to use the img_template for every image produced you can either not call the set function and instead add opts.label="img_template" to the params of the chunks you want to use it with, or override the img_template by specifying the params explicitly for the chunk.

提交回复
热议问题