1

I am working in R Markdown to create a PDF Output and trying to fit my outputs to a single page. I'm a bit over at the moment, and want to remove the extra white space around an image.

knitr::include_graphics(("File_Name.jpeg"))

I have tried par(mar(c(0,0,0,0)) which seemed promising based on the description here but that seems to scale the image.

I also tried using out.width but that didn't seem to impact the image at all.

enter image description here

  • Could you post a reproducible example? We don't know what the margins look like in the `jpeg` file, or how you included that code in your text. – user2554330 Aug 02 '20 at 09:02
  • Hi @user2554330 I'm not sure how to do that without adding all the specific details, but will try to make edits above. – Michael Soto Aug 07 '20 at 17:52
  • If you include the jpeg as an image in your question, I don't think StackOverflow will change its margins. Then just show us the code chunk that includes it with some text around it, and the YAML at the start of your document. (You should check that what you show us duplicates the problem you had.) – user2554330 Aug 07 '20 at 18:41
  • Thanks @user2554330! I'll keep that in mind for the future. I've figured this one out and will answer below. – Michael Soto Aug 07 '20 at 19:59

1 Answers1

1

Two steps resolved this for me.

First, I added the code below to the ggplot code which was creating the original graph image in a separate r script file, that I was saving and later inserting into the rmd file.

plot + 
theme(plot.margin = margin(0, 0, 0, 0, "cm"))

This helped to reduce the margins but there was still an extra space at the bottom which appeared in PDF Output files between blocks.

So, Second, following the guidance in https://stackoverflow.com/questions/59640925/rmarkdown-how-to-reduce-space-between-title-block-and-start-of-body-text

I added the code below after inserting the image (right before the first set of text) to reduce the extra spacing Markdown adds between blocks.

\vspace{-5truemm}