R Markdown documents are converted to PDF by first converting to a TeX file and then calling the LaTeX engine to convert to PDF. By default, this TeX file is removed, however if you want to keep it (e.g., for an article submission), you can specify the keeptex option. R Markdown allows you to combine chunks of R code with Markdown text and produce a nicely formatted HTML, PDF, or Word file, without having to know any HTML or LaTeX code or fuss with getting the formatting just right in a Microsoft Word DOCX file.
Introduction
Today, I will be talking about how to generate a nice pdf report with text, code, plots, and formulas using R markdown.
For those of you who are in a hurry, you will find the entire code at the end of this post. Simply skip to Step 2 to learn how to convert it into pdf.
Once again, I will explain how to do this in command line. Because why would anyone need graphical interfaces when they have Vim ?
Step 1 : Create a basic .Rmd file
Save the following lines in a file named, say, “my_report.Rmd” :
Step 2 : Convert .Rmd -> PDF
Command line in the same directory
>> Rscript -e “rmarkdown::render(‘./my_report.Rmd’)”
You sould find a file named my_report.pdf in the same directory.
The file should look like this :
Step 3 : Add some text, and a formula
Formulas are written using LaTex formatting.
Step 4 : Add some R code, and a plot
Rmd File To Pdf
More “generic” plot ideas here.
Step 5 : Change the plot size
In the above code, change
for
Step 5 : Summary
R Markdown Pdf Latex
Here is the entire sample code and the resulting PDF you can expect to have.