0

Using RStudio 2023.06.1 Build 524, R version 4.1.2 (2021-11-01), x86_64-pc-linux-gnu (64-bit) Linux Mint.

arr = rnorm(1000, 50, 20)
par(mfrow = c(1, 3))
boxplot(arr, ylim=c(0,70), col = "red")
boxplot(arr,ylim=c(0,70), col = "#EEEEEC")
boxplot(arr,ylim=c(0,70), col = "blue")

The output is moved to the right, where one of the plots is off the pdf. Like so: enter image description here

Suggestions?

Phil
  • 7,287
  • 3
  • 36
  • 66
mccurcio
  • 1,294
  • 5
  • 25
  • 44
  • How are you generating a PDF? Your code doesnt show this. Does it show up in your Rstudio "plots" viewer? Is this in markdown? Also, I assume you mean `arr = rnorm(1000, 50, 20)`? Providing a little more information about how you are encountering this problem will help you get better, faster help. – jpsmith Aug 03 '23 at 18:32
  • Yes, generating PDF, I am using Knitr to generate. Sure, but I'm not sure what else to add... – mccurcio Aug 03 '23 at 19:03
  • I can't replicate the issue using standard r-markdown pdf output https://i.imgur.com/pBnUKkG.png – Phil Aug 04 '23 at 02:06
  • 1
    Have you tried solution from this answer? https://stackoverflow.com/questions/16626462/figure-position-in-markdown-when-converting-to-pdf-with-knitr-and-pandoc – Eva Aug 04 '23 at 02:57

1 Answers1

0

Thanks to Eva for bringing this post to my attention: figure-position-in-markdown-when-converting-to-pdf-with-knitr-and-pandoc

The last answer gave me something that worked, (although I did modify it slightly).

ADD to Yaml

---
title: "title"
subtitle: "title2"
author: "By na"
pdf_document:
    fig_caption: yes
    fig_crop: no
    fig_height: 2
    fig_width: 3
    keep_tex: no
    number_sections: yes
    toc: yes
    toc_depth: 2
header-includes: 
- \usepackage{graphicx}
- \usepackage{float}
---

THEN by adding this to the first code chunk

{r LoadData, message=FALSE, warning=FALSE, include=FALSE}
# DO NOT SHOW IN FINAL REPORT
options(tinytex.verbose = TRUE)
options(digits = 5) 

#Load Libraries
Libraries <- c("knitr", "readr")
for (p in Libraries) { 
    library(p, character.only = TRUE)
}

opts_chunk$set(fig.align='center',
               external=TRUE,
               echo=TRUE,
               warning=FALSE,
               fig.pos='H'
               )
mccurcio
  • 1,294
  • 5
  • 25
  • 44