I am trying to rotate a plot 90 degrees together with its caption in Rmarkdown.
A minimal reproducible example code is:
---
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)
```
Rotating the plot itself using out.extra='angle=90'
works just fine, but having the caption rotate causes problems for me.
I have tried using @Jub0bs's suggestion (https://tex.stackexchange.com/a/101650), which looks like the following for me:
\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}
But it returns the following error:
! Package pdftex.def Error: File `CorrelatedRM125High.png' not found: using draft setting.
I tried @Danie Els's approach (https://tex.stackexchange.com/a/46337), which is to save the figure and caption in a box and then rotate the box, but it results in the same error.
I did not find sufficient information to fix this issue.
For me, it does not matter whether the rotated object is a plot or image - either way is fine.
I am hoping that maybe someone has had a similar experience and can guide me on how to proceed.
I would like to know whether there is a solution: i) within Rmarkdown (@CL.'s comment (here: Knitr: Turning the R chunk figure caption 90 degrees inline Latex) 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.
Thank you in advance!
EDIT:
As in the comments suggested, I provide a minimal reproducible example using sidewaysfigure
.
Taking an example-image does not result in any error:
\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}
Using another image of mine of the .jpeg format in the same directory as my actual image does not return any error either.
I am left with the question why it would result in an error if .png is used.
ANOTHER EDIT:
As suggested by @samcarter, which is to use the example example-image.png
, it doesn't return an error either!
\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}
Running:
\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}
Again results in the same error:
! Package pdftex.def Error: File `CorrelatedRM125High.PNG' not found: using draft setting.