'knitr multiple plot alignment

Here is a minimal example:

\documentclass{article}

\begin{document}
<<fig.height=4,out.width=\textwidth,echo=FALSE>>=
plot(1,1)
plot(2,2)
@ 

\newpage
<<fig.height=4,out.width=\textwidth,echo=TRUE>>=
plot(1,1)
plot(2,2)
@ 

\end{document}

Note the screenshots below. If echo=FALSE, horizontal alignment is off. The top plot is shifted to the right relative to the bottom plot. If echo=TRUE, horizontal alignment is correct

horizontal alignment is wrong

horizontal alignment is correct

How would I fix the first example to align correctly with echo=FALSE?

Thank you!



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source