Scaling Images

By default, images (JPEG, PNG, BMP, SVG) that are placed in panels are not scaled. This section demonstrates the four different scaling options available.

Here’s a multi-panel figure with four panels, to contain the images. In each case, we’ll use the copy of the R logo contained in the multipanelfigure package. This is a PNG file, 800 pixels wide and 700 pixels high, with a resolution of 300 dots per inch (DPI). That gives it a native size of 2.67" by 2.33“.

library(multipanelfigure)
figure <- multi_panel_figure(
  width = c(1, 5),
  height = c(1, 1, 4),
  unit = "inches")
r_logo <- system.file("extdata/Rlogo.png", package = "multipanelfigure")

By default, the image is not rescaled, which means that only the central part of the image is displayed.

(figure %<>% fill_panel(r_logo))
## Setting row to 1
## Setting column to 1

By setting scaling = "stretch", all the image is displayed, fitting the panel exactly, but the height-to-width ratio had been altered, distorting the image.

(figure %<>% fill_panel(r_logo, scaling = "stretch"))
## Setting row to 1
## Setting column to 2

Setting scaling = "fit" means that the image is shrunked or grown so that it just fits inside the panel without the height-to-width ratio being distorted.

(figure %<>% fill_panel(r_logo, scaling = "fit"))
## Setting row to 2
## Setting column to 1

Setting scaling = "shrink", works the same way as scaling = "fit" when the image is larger than the panel.

(figure %<>% fill_panel(r_logo, scaling = "shrink", row = 3, column = 1))

If the image is smaller than the panel, scaling = "shrink" works like scaling = "none".

(figure %<>% fill_panel(r_logo, scaling = "shrink", row = 2:3, column = 2))