Using knitr to make pdfs, the figures don't show when using the fig.align='center' option:
require(knitr)
opts_chunk$set(fig.align='center')
OR
```{r chunkname, fig.align='center'}
...code that makes figure...
```
Either way, no figures come out on the pdf when pressing the knit PDF button. But I remove the fig.align option and the figures appear, left aligned.
This was an old problem that should have been solved with the 1.8 knitr version, but still have the same problem :(
Any ideas?
Thank you!
You need to set GLOBAL options for this. I have this header as standard for my docs, altering it as required:
### Set global and markdown global options
```{r global.options, include = TRUE}
knitr::opts_chunk$set(
cache = TRUE, # if TRUE knitr will cache the results to reuse in future knits
fig.width = 10, # the width for plots created by code chunk
fig.height = 10, # the height for plots created by code chunk
fig.align = 'center', # how to align graphics in the final doc. 'left', 'right', 'center'
fig.path = 'figs/', # file path to the directory where knitr shall store the graphics files
results = 'asis', # knitr will pass through results without reformatting them
echo = TRUE, # in FALSE knitr will not display code in the code chunk above it's results
message = TRUE, # if FALSE knitr will not display any messages generated by code
strip.white = TRUE, # if FALSE knitr will not remove white spaces at the beg or end of code chunk
warning = FALSE) # if FALSE knitr will not display any warning messages in the final document
```
Also, please, check that you have set output type in the beginning of the doc:
---
title: "blah-blah"
author: "Denis Rasulev"
date: "November 2015"
output: pdf_document
---
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