getRatioCoords {plotfunctions} | R Documentation |
Move a vector n elements forward or backward.
Description
Move a vector n elements forward or backward.
Usage
getRatioCoords(
ratio,
width = NULL,
height = NULL,
input = c("coords", "prop"),
...
)
Arguments
ratio |
Numeric, height : width ratio. If |
width |
The desired width in plot coordinates or proportions. If not specified (NULL), the maximal width fitting in the plot region is returned. |
height |
The desired height in plot coordinates or proportions. If not specified (NULL), the maximal height fitting in the plot region is returned. |
input |
Unit of input width and height, 'coords' (plot coordinates, default), or 'prop' (proportions of plot region). |
... |
Optional arguments: |
Value
A list with 5 elements:
-
width
: width of the element in x-axis coordinates; -
height
: height of the element in y-axis coordinates; -
ratio
: provided ratio (for confirmation); -
x
: two-number vector with x-coordinates of left and right sides; -
y
: two-number vector with y-coordinates of bottom and top sides.
Author(s)
Jacolien van Rij
See Also
Other Utility functions:
findAbsMin()
,
find_n_neighbors()
,
firstLetterCap()
,
getArrowPos()
,
getDec()
,
getRange()
,
get_palette()
,
group_sort()
,
inch2coords()
,
isColor()
,
list2str()
,
move_n_point()
,
orderBoxplot()
,
se()
,
sortGroups()
Examples
data(img)
emptyPlot(100, c(50, 100), h0=0, v0=0)
# calculate height : width ratio of image:
im.r <- dim(img$image)[1]/dim(img$image)[2]
p <- getRatioCoords(ratio=im.r, width=20)
# inspect p:
p
# No position specified, so centered:
plot_image(img, type='image', add=TRUE,
xrange=p$x, yrange=p$y)
# ... or we could provide a position:
p <- getRatioCoords(ratio=im.r, width=20,
xleft=20, ybottom=60)
plot_image(img, type='image', add=TRUE,
xrange=p$x, yrange=p$y)
# Using proportions of plot region:
p <- getRatioCoords(ratio=im.r, height=.5,
xleft=0, ytop=1, input='prop')
plot_image(img, type='image', add=TRUE,
xrange=p$x, yrange=p$y)
# Changing the ratio to square:
p <- getRatioCoords(ratio=1, height=.5,
xright=1, ybottom=0, input='prop')
plot_image(img, type='image', add=TRUE,
xrange=p$x, yrange=p$y)
# ... and to a long rectangle:
p <- getRatioCoords(ratio=.5, height=1,
xright=1, ybottom=0, input='prop')
plot_image(img, type='image', add=TRUE,
xrange=p$x, yrange=p$y,
replace.colors=list('#B.+'='#FF000033'),
border='red')