Description Usage Arguments Value Author(s) Examples
Convert Between Different Available Units That Measure Points on a Plot
1 | convertUnits(from, value, to, side = NULL, axis = NULL, region = "plot")
|
from |
Units one wishes to convert from. Allowed values are "line", "data", and "proportion". |
value |
Numeric value(s) of the coordinate(s) one wishes to convert. |
to |
Units one wishes to convert from. Allowed values are "line", "data", and "proportion". |
side |
Integer giving the side of the plot to count lines from. |
axis |
One of "x" or "y", giving the axis a proportion should be calculated from. |
region |
Required when either from or to has the value "proportion". Must be one of "device", "figure", "plot", or "data". Defaults to "plot". |
Numeric value(s) of the input coordinates converted into the new units.
Jasper Watson
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 | ## Not run:
## Illustrate where the lines fall when using mtext:
plot(1:10)
mtext(1:26, line = -(1:26), side = 1, col = 'blue')
x <- convertUnits('line', 0:(-26), 'data', side = 1)
abline(h = x, col = 'red', lty = 2)
## Show how proportions of a plot can be identified:
plot(seq(as.Date('2018-01-01'), as.Date('2019-01-01'), length.out = 10), 1:10,
pch = 19)
## Identify the "center" of the plot.
abline(h = convertUnits('proportion', 0.5, 'data', axis = 'y'),
col = 'red', lwd = 4)
abline(v = convertUnits('proportion', 0.5, 'data', axis = 'x'),
col = 'blue', lwd = 4)
print(convertUnits('proportion', 0.5, 'data', axis = 'y'))
## as.Date is needed because convertUnits returns a numeric value.
print(as.Date(convertUnits('proportion', 0.5, 'data', axis = 'x'),
origin = '1970-01-01'))
## Change the region we are defining the proportions from.
abline(v = convertUnits('proportion', 0.75, 'data', axis = 'x', region = 'plot'),
col = 'darkgreen', lwd = 4)
abline(v = convertUnits('proportion', 0.75, 'data', axis = 'x', region = 'device'),
col = 'orange', lwd = 4)
## End(Not run)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.