coord_aspect: Fixed aspect ratio relative to X/Y limits

View source: R/coord_aspect.R

coord_aspectR Documentation

Fixed aspect ratio relative to X/Y limits

Description

Uses a given aspect ratio for a ggplot based on the limits provided.

Usage

coord_aspect(ratio = 1, xlim = NULL, ylim = NULL, expand = FALSE, clip = "on")

Arguments

ratio

Numeric ratio, default 1 (for square). Ratios should be of the form height / width.

xlim

Numeric vector of length 2, limits for x axis

ylim

Numeric vector of length 2, limits for y axis

expand

Logical, default FALSE, whether to expand

clip

Whether to clip to plot, default "on"

Details

If the range of X values is 10 to 200 and the range of Y values is 20 to 60, then a square aspect ratio would require a ratio of (200 - 10) / (60 - 40). A landscape 16:9 aspect ratio would be (9/16) * (200-10) / (60-40). This is an annoying amount of things to type out if you're fiddling around with the limits and aspect ratio.

Value

coordinate ggproto


tsostarics/sostools documentation built on June 1, 2025, 10:20 p.m.