getRatioCoords: Move a vector n elements forward or backward.

Description Usage Arguments Value Author(s) See Also Examples

View source: R/util.R

Description

Move a vector n elements forward or backward.

Usage

1
2
3
4
5
6
7
getRatioCoords(
  ratio,
  width = NULL,
  height = NULL,
  input = c("coords", "prop"),
  ...
)

Arguments

ratio

Numeric, height : width ratio. If ratio > 1, the width is larger than the height, if ration < 1, the height is larger than the width.

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: xcenter, xleft, or xright, and ycenter, ybottom, or ytop could be specified. If not specified, the width and height are centered around the center of the plot.

Value

A list with 5 elements:

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

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
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')

plotfunctions documentation built on April 28, 2020, 5:10 p.m.