I am working towards writing a textbook using R Bookdown, and I want to include pictures in the margins of the text. However, after trying multiple methods none of them seem to actually populate the image in the correct place. I have tried all the options in r bookdown manual and the instructions for using tufte style https://bookdown.org/yihui/rmarkdown/tufte-figures.html.
To make sure I am not having problems with conflicting packages I have been creating a fresh project then pasting the following code into the end of the index.Rmd file.
{r fig-margin, fig.margin=TRUE}
knitr::include_graphics('apple.png')
^
{marginfigure, echo = TRUE}
knitr::include_graphics('apple.png')
The following image is the result of me either knitting the index.Rmd document or building the whole book using the build menu:

As you can see, the images are populating but certainly not in the margin. Any help or guidance would be greatly appreciated!


I do not know how to use r chunk inserting picture in the margin. Here is my document using latex in Rmarkdown insert the compamy logo in left-top margin.