Plot options

Reporting with R Markdown

Amy Peterson

Head of Core Curriculum at DataCamp

Figure dimensions

  • fig.width
  • fig.height
Reporting with R Markdown

Figure dimensions

Code to set 5 by 3 figure dimensions using fig.width and fig.height

Knit document with 5 by 3 figure dimensions using fig.width and fig.height

Reporting with R Markdown

Figure dimensions

Code to set 5 by 3 figure dimensions using fig.dim

Knit document with 5 by 3 figure dimensions using fig.dim

Reporting with R Markdown

Output dimensions

  • out.width
  • out.height
Reporting with R Markdown

Output dimensions

Code to set output dimensions at 50 percent using out.width

Knit document with 50 percent output dimensions using out.width

Reporting with R Markdown

Figure alignment

  • fig.align
    • 'left'
    • 'right'
    • 'center'
Reporting with R Markdown

Figure alignment

Code to set left figure alignment using fig.align

Knit document with left figure alignment using fig.align

Reporting with R Markdown

Local vs. global options

Setting figure alignment locally in individual code chunks

Setting figure alignment globally in the setup code chunk

Reporting with R Markdown

Setting options globally

Setting left figure alignment globally in the setup code chunk

Knit document with global left figure alignment

Reporting with R Markdown

Adding captions

Adding figure caption with fig.cap

Knit document with plot and figure caption

Reporting with R Markdown

Let's practice!

Reporting with R Markdown

Preparing Video For Download...