By default, R Markdown employs inch as a unit of figure size. You can change it by hook_figure_unit.


  • This hook must not run twice in a document. Otherwise, you will face unexpected figure size.
  • RStudio IDE do not detect the hook and treats fig.width and fig.height in inches.
  • This hook sets NULL to the fig.retina chunk option.

Basic usage

hook_figure_unit() changes to the unit of figure size to millimeters. Note that this hook will not change the default size.

#> fig.retina is set NULL
# fig.width=50, fig.height=50 (50mm * 50mm)

Other units

You may change default unit by the first argument, unit.

Choices are followings:

#>  [1] "angstrom"   "nm"         "um"         "mm"         "cm"        
#>  [6] "dm"         "m"          "km"         "inch"       "ft"        
#> [11] "foot"       "feet"       "yd"         "yard"       "fathom"    
#> [16] "mi"         "mile"       "naut_mi"    "au"         "light_yr"  
#> [21] "light_year" "parsec"     "point"