This simple function is useful for adjusting x and y coordinate ranges xlim and ylim in order to maintain a desired display ratio. The latter must be given, the former will be adjusted.

xlimFromYlim(ylim, centerX = 0, x_to_y = 16/9)

Arguments

ylim

Numeric vector of length 2; the fixed lower and upper boundary of the vertical coordinate range

centerX

The horizontal coordinate which the output range is to be centered around (default = 0)

x_to_y

The desired ratio of the horizontal (x) to the vertical (y) range. Default is 16/9, a display ratio frequently used for computer or mobile screens

Value

A numeric vector of length 2; the lower and upper boundary of the resulting vertical coordinate range

Details

For certain purposes, e.g. producing a graph that exactly matches a screen, the x and y coordinates must be adjusted to match a given display ratio. If the vertical range, ylim, the desired ratio, x_to_y and the desired center of the x-range, centerX, are provided, this function returns an adpated vertical range, that can be used as ylim in any plot including phasePortrait.

See also

Other helpers: vector2String(), ylimFromXlim()

Examples

# Make a phase portrait of a pretty function that fully covers a
# plot with a display aspect ratio of 5/4.

# 9 inch wide window with 5/4 display ratio (x/y)
# \donttest{
# x11(width = 9, height = 9 * 4/5) # Screen device commented out
                                   # due to CRAN test requirements.
                                   # Use it when trying this example
ylim <- c(-8, 7)
xlim <- xlimFromYlim(ylim, centerX = 0, x_to_y = 5/4)
op <- par(mar = c(0, 0, 0, 0), bg = "black") # Omit all plot margins
phasePortrait("exp(cosh(1/(z - 2i + 2)^2 * (1/2i - 1/4 + z)^3))", pType = "pm",
xlim = xlim, ylim = ylim, # Apply the coordinate ranges
xaxs = "i", yaxs = "i",   # Allow for now room between plot and axes
nCores = 2) # Max. two cores allowed on CRAN
            # not a limit for your own use
par(op)
# }