Refine plots & add variables to Rmarkdown reports - Earth analytics course module

Welcome to the first lesson in the Refine plots & add variables to Rmarkdown reports module. This tutorial set covers some basic things you can do to refine your plots in Rmarkdown document. It covers plotting in grids, adding titles to plotRGB() plots and refining the width and height of plots to optimize space.

Lesson 1. Add variables to an RMD report R.

Learning Objectives

After completing this tutorial, you will be able to:

  • Add a variable to the markdown chunk in your rmd report.

What you need

You will need a computer with internet access to complete this lesson and the data for week 6 of the course.

Download Week 6 Data (~500 MB)

Automating report content

Let’s pretend that we’ve calculated a value in our code and we want to include it in our R Markdown report but we don’t want to include the code. Maybe it’s a number that we want to appear in the TEXT of our report - not as a code chunk output. How do we do that?


total_area <- (800 * 7) / 2

We can add any variable that we want to a report using the syntax

"r total_area"

However replace the double quotes “” with ticks `

There are 2800 km of burned area according to modis.

Where the markdown text is surrounded by ticks. Followed by the language “r” and then the variable that we want to print in our report! This is very useful when we are trying to create a fully automated report. As we update the data, the output numbers if our report also update!

Leave a Comment