Option 1: Export figure and then include it again
In a similar manner to this answer to Plotly as png in knitr/rmarkdown
the current hack is to export the figure and then load in the produced file. As a small example (which you could adapt) there is
---
title: "Diamond prices"
author: "Oliver"
date: "6^th^ May 2020"
output:
pdf_document:
fig_caption: yes
header-includes:
- \usepackage{cleveref}
fontsize: 12pt
always_allow_html: yes
---
# Making a plot
```{r, echo=FALSE, include=FALSE}
options(shiny.testmode = TRUE)
library(knitr)
library(plotly)
data("diamonds")
```
```{r , echo=FALSE, include=FALSE}
fig <- plot_ly(diamonds, x = ~carat, y = ~price, type="scatter", mode="markers", color = ~clarity, width =200, height = 150)
orca(fig, file="diamonds.png")
```
![\label{fig:fig_prices_of_diamonds}The price of diamonds depnds on their size.](diamonds.png)
We can see in \Cref{fig:fig_prices_of_diamonds} how expensive diamonds can be.
which produces
Option 2: Use webshot
Based on comments in this answer to Change output width of plotly chart size in R Markdown PDF output an alternative is to capture the image automatically using wesbot. Simply run the following once in the R console to install webshot (and PhantomJS which webshot in turn uses):
install.packages('webshot')
webshot::install_phantomjs()
One you have this you can adapt the above example to use instead:
```{r fig:fig_prices_of_diamonds, echo=FALSE, include=TRUE, fig.cap="\\label{fig:fig_prices_of_diamonds}The prices of diamonds increases perhaps?"}
plot_ly(diamonds, x = ~carat, y = ~price, type="scatter", mode="markers", color = ~clarity, width =400, height = 250)
```
We can see in \Cref{fig:fig_prices_of_diamonds} how expensive diamonds can be.
which is much cleaner code.
I would like to include title/date/author/supervisor(costum command) in the rmd yaml header. How do I achieve this?
So simple:
---
title: A theme
subtitle: A modern beamer and Rmarkdown template
date: \today
author: XY
supervisor: YZ
institute: Institution or Company of High Esteem
output: beamer_presentation
---
# test
This is a test.
If you compile this, this produce a title frame and the only thing ignored of the YALM header is YZ
.
The reason is that there are not any $supervisor$
variable nor $if(supervisor)$ <whatever> $else$ <whatever> $endif$
in the default template. This link the second question:
Does anyone know of a good example/walk-through for integrating costum tex templates?
cd /usr/share/pandoc/data/templates # In Linux Mint
nano default.beamer # change "nano" to your favorite editor
OK, ok, some simpler to start: simplest.template
:
\documentclass{beamer}
\begin{document}
\begin{frame}
$body$
\end{frame}
\end{document}
Test.Rmd:
---
output:
pdf_document:
template: simplest.template
---
This is the body.
Too simple? Ok, ok, I know, ... some less simple: the supervisor.template
:
\documentclass{beamer}
\begin{document}
\begin{frame}
$if(supervisor)$ Supervisor: $supervisor$
$else$ I have not a supervisor $endif$
\end{frame}
\end{document}
Test2.Rmd:
---
supervisor: YZ
output:
pdf_document:
keep_tex: yes
template: supervisor.template
---
This is ignored text.
... And so on.
Best Answer
This can be accomplished with
"-r", "markdown-auto_identifiers"
It can be specified in the YAML with
or in a function like
bookdown::pdf_book
using thepandoc_args
argumentpandoc_args = c(pandoc_args, "--top-level-division=chapter", "-r","markdown-auto_identifiers")