Essentially, I have a Rmd document configured like this:
---
title: "Example"
author: "me"
date: "December 2014"
output:
pdf_document:
fig_caption: yes
keep_tex: yes
--
Then, in the document, I use ggplot2
to show some charts, for example:
```{r myLabel, fig.cap='My Caption'}
qplot(1:10, 10:1)
```
Now, for some reason I cannot explain or investigate any deeper than this, the produced TeX does not contain the figure environment, even if I force it with fig.env='figure'
. Instead, the TeX only has the includegraphics
command:
\includegraphics{journal_files/figure-latex/myLabel-1.pdf}
Other figures in the same document do have the figure environment, with the caption. I.e., the TeX output "Knit PDF" should be producing is:
\begin{figure}[htbp]
\centering
\includegraphics{journal_files/figure-latex/myLabel-1.pdf}
\caption{My Citation}
\end{figure}
The R Markdown log window only shows irrelevant stuff:
label: myLabel (with options)
List of 2
$ fig.cap: chr "My Caption"
$ fig.env: chr "figure"
cropping journal_files/figure-latex/myLabel-1.pdf
PDFCROP 1.38, 2012/11/02 - Copyright (c) 2002-2012 by Heiko Oberdiek.
How do I either
As in other Rmd documents, you can use the fig. cap chunk option to provide a figure caption, and adjust figure sizes using the fig. width and fig. height chunk options, which are specified in inches, and will be automatically scaled down to fit within the handout margin.
For example, # Say Hello to markdown . A single hashtag creates a first level header. Two hashtags, ## , creates a second level header, and so on. italicized and bold text - Surround italicized text with asterisks, like this *without realizing it* .
To add an image in markdown you must stop text editing, and you do this with the command [Alt text] precedeed by a ! Then you have to add the path to the image in brackets. The path to the image is the path from your directory to the image.
Chunk options The initial line in a code chunk may include various options. For example, echo=FALSE indicates that the code will not be shown in the final document (though any results/output would still be displayed). You use results="hide" to hide the results/output (but here the code would still be displayed).
Turns out, the solution is quite simple: the RMarkdown compiler does not show captions for two consecutive figures, like this:
```{r myLabel1, fig.cap='My Caption 1'}
qplot(1:10, 10:1)
```
```{r myLabel2, fig.cap='My Caption 2'}
qplot(1:10, 10:1)
```
or for a figure not separated from the text in a new paragraph like this:
```{r myLabel1, fig.cap='My Caption 1'}
qplot(1:10, 10:1)
```
As shown in Fig. 2, the inter-galactic distances are strongly correlated with the observed redshift ...
In this setting, the captions are missing and no figure environment is created in the TeX file.
Instead, between the two plots, there must be at least two spacing (newline) characters. I.e., this works nicely and both captions show:
```{r myLabel1, fig.cap='My Caption 1'}
qplot(1:10, 10:1)
```
```{r myLabel2, fig.cap='My Caption 2'}
qplot(1:10, 10:1)
```
Even though this is a feature to make it possible to include inline graphics, it would be nice if there was a warning message for figures with a fig.cap argument that does not show up.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With