title: Rmarkdown: Rotate image/figure together with its caption
body: <p>I am trying to rotate a plot 90 degrees together with its caption in Rmarkdown. </p>
  
  <p>A minimal reproducible example code is: </p>
  
  <pre><code>---
  title: "Checking"
  author: "Tester"
  date: "6/7/2020"
  header-includes:
     - \usepackage{rotating}
  output: 
    pdf_document:
      fig_caption: yes
      number_sections: true
  ---
  {
  \hypersetup{linkcolor=black}
  \tableofcontents 
  \listoffigures
  \listoftables
  }
  \newpage
  
  ```{r  rmplots 0.125 high, fig.align="center", fig.scap="Check", out.extra='angle=90',echo=FALSE, fig.cap="Check"}
  plot(1)        
  abline(0, 1)    
  ```
  </code></pre>
  
  <p>Rotating the plot itself using <code>out.extra='angle=90'</code> works just fine, but having the caption rotate causes problems for me. </p>
  
  <p>I have tried using @Jub0bs's suggestion (<a href="https://tex.stackexchange.com/a/101650">https://tex.stackexchange.com/a/101650</a>), which looks like the following for me:</p>
  
  <pre><code>\begin{sidewaysfigure}
      \centering
  
          \includegraphics{CorrelatedRM125High.png}
  
      \caption{Box plot of number of positions sent per iteration using this scheme}
      \label{fig:awesome_image}
  \end{sidewaysfigure}
  </code></pre>
  
  <p>But it returns the following error:</p>
  
  <blockquote>
    <p>! Package pdftex.def Error: File `CorrelatedRM125High.png' not found:
    using draft setting.</p>
  </blockquote>
  
  <p>I tried @Danie Els's approach (<a href="https://tex.stackexchange.com/a/46337">https://tex.stackexchange.com/a/46337</a>), which is to save the figure and caption in a box and then rotate the box, but it results in the same error.</p>
  
  <p>I did not find sufficient information to fix this issue.</p>
  
  <p><strong>For me, it does not matter whether the rotated object is a plot or image - either way is fine.</strong></p>
  
  <p>I am hoping that maybe someone has had a similar experience and can guide me on how to proceed. </p>
  
  <p>I would like to know whether there is a solution: i) within Rmarkdown (@CL.'s comment (here: <a href="https://stackoverflow.com/q/31597285/11783513">Knitr: Turning the R chunk figure caption 90 degrees inline Latex</a>) suggests that knitr does not provide this option, but the comment was already from some time ago - maybe there is a fix now?), or ii) a suggestion on how to incorporate Latex-code but at the same time avoid the error message from above. </p>
  
  <p>Thank you in advance!</p>
  
  <hr>
  
  <p>EDIT:
  As in the comments suggested, I provide a minimal reproducible example using <code>sidewaysfigure</code>.</p>
  
  <p>Taking an example-image does not result in any error:</p>
  
  <pre><code>\begin{sidewaysfigure}
      \centering
          \includegraphics{example-image-a}
      \caption{Box plot of number of positions sent per iteration using this scheme}
      \label{fig:awesome_image}
  \end{sidewaysfigure}
  </code></pre>
  
  <p>Using another image of mine of the .jpeg format in the same directory as my actual image does not return any error either.</p>
  
  <hr>
  
  <p>I am left with the question why it would result in an error if .png is used.</p>
  
  <hr>
  
  <p>ANOTHER EDIT: </p>
  
  <p>As suggested by @samcarter, which is to use the example <code>example-image.png</code>, it doesn't return an error either!</p>
  
  <pre><code>\newpage
  
  \begin{sidewaysfigure}
      \centering
          \includegraphics{example-image.png}
      \caption{Box plot of number of positions sent per iteration using this scheme}
      \label{fig:awesome_image}
  \end{sidewaysfigure}
  </code></pre>
  
  <p>Running:</p>
  
  <pre><code>\begin{sidewaysfigure}
      \centering
          \includegraphics{CorrelatedRM125High.PNG}
      \caption{Box plot of number of positions sent per iteration using this scheme}
      \label{fig:awesome_image}
  \end{sidewaysfigure}
  </code></pre>
  
  <p>Again results in the same error:</p>
  
  <blockquote>
    <p>! Package pdftex.def Error: File `CorrelatedRM125High.PNG' not found:
    using draft setting.</p>
  </blockquote>