IBTL
IBTL

Reputation: 131

Resizing images in RMarkdown

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.

Upvotes: 11

Views: 23435

Answers (4)

lgadar
lgadar

Reputation: 169

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
```

Upvotes: 13

JohnCoene
JohnCoene

Reputation: 2261

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>

Upvotes: 0

phabi
phabi

Reputation: 372

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

Upvotes: 2

Pablo Casas
Pablo Casas

Reputation: 908

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)

Upvotes: 5

Related Questions