I have been using the default setting for figure floating according to the R Markdown Cookbook (6.5 Control the placement of figures | R Markdown Cookbook) but sometimes figures float forward to the top of the next page creating a break in a code chunk which makes the whole thing hard to read - especially since the figure that floated was from one example, and lands in the middle of the next example.
I have added the lines:
\usepackage{float}
\floatplacement{figure}{H}
to my preample.tex, but as predicted in section 6.5.2, this stops figures from floating at all and is not exactly right either.
All I really want is for code chunks to not be broken by figures - being broken by page breaks seems OK, but when a figure floats to the top of a page the break seems really off.
Looking at the various posts on this, figure floating seems to be a real sticking point, but I haven't found any answers related to the special nature of code chunks.
Any suggestions on how to prevent code chunks from being split by floating figures?