Use the option self_contained: no if you are using html_document, or keep_tex: yes if you use pdf_document, so that rmarkdown will not remove the figure files after rendering the output document.

matlab,plot,matlab-figure,figures

Here is a way to do it. You need to change the YTick and XTick properties of the axes, as well as the YLim property for the top plot, since by default Matlab tries to fit the axis with the range of data you have. clear clc x = linspace(0,2);...