Resizing images in RMarkdown

人走茶凉 提交于 2019-12-31 14:20:31

问题


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.


回答1:


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



回答2:


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)




回答3:


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




回答4:


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>


来源:https://stackoverflow.com/questions/26881866/resizing-images-in-rmarkdown

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!