Skip to contents

This function retrieves the minimum and maximum x and y dimensions of a ggplot object. Note that it is the dimension of the plot within the x and y axis and not the dimensions of the actual output image itself. This may be useful for numerical computations when modifying plots, but can be slow since it builds the actual plot first.

Usage

getPlotDims(plt)

Arguments

plt

A ggplot object.

Value

A list with elements xr (a vector of xmin and xmax) and yr (a vector of ymin and ymax).

Examples

library(ggplot2)
getPlotDims(ggplot(mtcars) + geom_point(aes(mpg, cyl)))
#> $xr
#> [1] 10.4 33.9
#> 
#> $yr
#> [1] 4 8
#>