11

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? I Can't use html, this is markdown to pdf.

Eric Leschinski
  • 146,994
  • 96
  • 417
  • 335
IBTL
  • 131
  • 1
  • 1
  • 3
  • Check whether this is helpful http://stackoverflow.com/questions/14675913/how-to-change-image-size-markdown – Keniajin Nov 12 '14 at 07:58

4 Answers4

13

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
```
Eric Leschinski
  • 146,994
  • 96
  • 417
  • 335
lgadar
  • 169
  • 1
  • 8
5

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)

Pablo Casas
  • 868
  • 13
  • 15
  • In my experience, changing fig.height and fig.width will NOT cause the text or numbers to have a changed size. – jciloa May 01 '17 at 07:54
2

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 {}.

phabi
  • 362
  • 3
  • 10
0

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>
JohnCoene
  • 2,107
  • 1
  • 14
  • 31