When using a fixed-aspect coordinate system, fixed_plot_aspect() expands either the width or height of the plot to ensure that the output has dimensions that make sense. This is a useful workaround for getting reasonable-shaped plots when using ggplot2::coord_sf() or ggplot2::coord_fixed() when the data happen to be aligned vertically or horizontally.

fixed_plot_aspect(ratio = 1)

Arguments

ratio

The desired aspect ratio (width / height)

Value

A ggplot2::layer() that can be added to a ggplot2::ggplot().

Examples

library(ggplot2)
df <- data.frame(x =  0:5, y =  seq(0, 10, length.out = 6))
ggplot(df, aes(x, y)) +
  geom_point() +
  fixed_plot_aspect(ratio = 1) +
  coord_fixed()