3

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.

M M
  • 429
  • 5
  • 13
  • Why do you wrap `\includegraphic` into a `tikzpicture`? – samcarter_is_at_topanswers.xyz Jun 07 '20 at 14:10
  • Can you make a [mre] of what you tried with `sidewaysfigure`? – samcarter_is_at_topanswers.xyz Jun 07 '20 at 14:10
  • Thank you for taking interest into this question. I wrapped it into a tikzpicture, because the answer I mentioned (https://tex.stackexchange.com/a/101650 structured it like this. I tried both, keeping it and removing it, in any case I end up with the same error. – M M Jun 07 '20 at 14:16
  • Regarding the minimal reproducible example, what would you like to see more (beside the sidewaysfigure example from above)? – M M Jun 07 '20 at 14:18
  • 1
    The answer from tex.se was using a tikzpicture and not `\includegraphics`. Remove the tikzpicture if you don't use tikz – samcarter_is_at_topanswers.xyz Jun 07 '20 at 14:20
  • 1
    About the mre: a ready to copy&paste code like you show for your r plot would be best. This will make sure that we start from the same code base. Of course I could try to puzzle something together, but there is no guarantee that this would show the same problem you face. (for the example you could use `example-image` instead of `CorrelatedRM125High.png`, which should be available is most tex installations) – samcarter_is_at_topanswers.xyz Jun 07 '20 at 14:23
  • I see, thank you very much. I am at it just now. – M M Jun 07 '20 at 14:23
  • I gave the mre. Is this what you expected? – M M Jun 07 '20 at 14:39
  • 1
    Interesting that it works with other images. Can you a) double check that CorrelatedRM125High.png is spelled correctlt, including capitalisation and the file is not called say CorrelatedRM125High.PNG ? b) try with `\includegraphics{example-image.png}` to exclude that png as such is causing a problem – samcarter_is_at_topanswers.xyz Jun 07 '20 at 14:41
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/215470/discussion-between-m-m-and-samcarter-is-at-topanswers-xyz). – M M Jun 07 '20 at 14:48

0 Answers0