As of 2019, perhaps the best solution is to make a Latex preamble for your Rmd file as explained here. In other words:
Save following preamble.tex file in your working directory:
\usepackage{float}
\let\origfigure\figure
\let\endorigfigure\endfigure
\renewenvironment{figure}[1][2] {
\expandafter\origfigure\expandafter[H]
} {
\endorigfigure
}
Note that the "H" tells the image to go where you insert it. Then call for the preamble.tex in the YAML header of your Rmd file:
---
title: "example"
author: "you"
date: "`r format(Sys.time(), '%d %B %Y')`"
output:
rmarkdown::pdf_document:
fig_caption: yes
includes:
in_header: preamble.tex
---
