keepFigRatio {plotfunctions}R Documentation

Calculate the height or width in plot coordinates to keep a given ratio relative to the figure.

Description

Calculate the height or width in plot coordinates to keep a given ratio relative to the figure.

Usage

keepFigRatio(input, original = c(1024, 768), side.input = 1)

Arguments

input

A number in units of x- or y-axis (determined by side.input argument).

original

Two-number vector representing the width and height of the original rectangle; alternatively, if only one number is provided, this is interpreted as the width:height ratio.

side.input

Number representing the axis associated with the number(s) specified in the argument input, with 1=bottom (default), 2=left, 3=top, 4=right. The output is adjusted accordingly.

Value

Width and height in x- and y-units

See Also

Other Utility functions: findAbsMin(), find_n_neighbors(), firstLetterCap(), getArrowPos(), getDec(), getRange(), getRatioCoords(), get_palette(), group_sort(), inch2coords(), isColor(), list2str(), move_n_point(), orderBoxplot(), se(), sortGroups()

Examples

# add centered square to plot,
# while plot window is not squared
dev.new(width=5, height=4)
emptyPlot(1,1, bty='o')
size1 = keepFigRatio(.5, original=c(1,1))
size2 = keepFigRatio(.5, original=c(1,1), side.input=2)
rect(xleft=.5-(size1$x/2),
     xright=.5+(size1$x/2),
     ybottom=.5-(size1$y/2),
     ytop=.5+(size1$y/2),
     col="gray")
rect(xleft=.5-(size2$x/2),
     xright=.5+(size2$x/2),
     ybottom=.5-(size2$y/2),
     ytop=.5+(size2$y/2),
     col=alpha("#FF3300"), border=NA)
rect(xleft=.25, xright=.75,
     ybottom=.25, ytop=.75,
     lwd=2, border="#0066FF")



[Package plotfunctions version 1.5 Index]