Resizing images in RMarkdown

后端 未结 4 859
迷失自我
迷失自我 2021-02-04 12:37

I\'m trying to convert a R markdown .Rmd document to .pdf. Unfortunately, the images are too large. Is there any way to change the size of the image?

相关标签:
4条回答
  • 2021-02-04 13:08

    There is a simple way to resize Images and still being able to add Captions. Use the following syntax within your RMarkdown code and place the Image's Caption beneath the Image:

    <!-- Einbinden von Bildern in RMarkdown -->
    \begin{figure}
    \centerline{\includegraphics[width=0.5\textwidth]{your_image_name.png}}
    \caption{Entitäten zur Persistierung der Special Notifications}
    \end{figure}
    

    To scale the image just adapt the width-value from 0.5 to some other percentage-value fitting your needs.

    If you don't want to center the images, just remove the \centerline - Command with it's opening and closing brackets {}.

    0 讨论(0)
  • 2021-02-04 13:22

    To the best of my knowledge rmarkdown html formats come with Bootstrap. I add the img-responsive with some javascript (at the bottom of my document).

    <script>
      var d = document.document.getElementsByTagName("img");
      d.className += " img-responsive";
    </script>
    
    0 讨论(0)
  • 2021-02-04 13:28

    I found a comfortable solution by the combination of fig.height, fig.width, dpi and out.width.

    You can set global parameters at the top by:

    knitr::opts_chunk$set(out.width="400px", dpi=120)

    You can overwrite these properties in any chunk, just set the parameters you need.

    dpi increases the quality image, so you have to adjust by the other parameters.

    out.width adjust the size once the image is created.

    Decreasing values in fig.height and fig.width will cause the text/numbers to be bigger (same as reducing image window in Rstudio)

    0 讨论(0)
  • 2021-02-04 13:31

    Use this at the beginning of a chunk:

    Decimals assigned to fig.height and fig.width are interpreted as inches. Other units of measure also allowed if explicit.

    ```{r, echo=FALSE, fig.height=2.7, fig.width=9}
    #your R code here
    ```
    
    0 讨论(0)
提交回复
热议问题