I use R Markdown to build a PDF, and I use ggplot2 to plot. without hiding the code everything is right. (ChickWeight is a default dataset)
ggplot2
ChickWeight