Description Usage Arguments Examples
Based on an original coordinate, define a new one that is regular and as close as possible to the original one, overall.
1 |
x |
vector containing the original coordinate; there are methods for |
start |
initial guess for the starting point of the regular coordinate. If |
step |
initial guess for the step of the regular coordinate. If |
control |
passed as the |
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 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 | # Plot original and regularised coordinates
pc <- function(x, xr, ...) {
plot(x, rep(1, length(x)), type="n",
xlim=range(c(x, xr)), ylim=c(0.8, 1.2),
ylab="", yaxt="n")
abline(h=1, lty="22")
segments(x0=x, y0=1, x1=x, y1=1.1)
segments(x0=xr, y0=1, x1=xr, y1=0.9)
axis(2, at=c(1.05, 0.95), labels=c("original", "regularised"))
}
# Numeric coordinate
# Already regular coordinate
x <- 1:10
pc(x, regularise_coord(x))
# Random coordinate
set.seed(1)
x <- sort(runif(10))
pc(x, regularise_coord(x))
pc(x, regularise_coord(x, step=0.05))
# Almost regular coordinate
set.seed(1)
x <- jitter(1:10, factor=0.5)
pc(x, regularise_coord(x))
# Regular coordinate with additions
x <- sort(c(1:10, 5.2))
pc(x, regularise_coord(x))
# Regular coordinate with deletions
x <- (1:10)[-c(3)]
pc(x, regularise_coord(x))
# Regular coordinate with outliers
x <- c(1:10, 12.9)
pc(x, regularise_coord(x))
x <- c(1:10, 19.9)
pc(x, regularise_coord(x))
# -> not ideal...
# Times
set.seed(1)
x <- as.POSIXct("2010-01-01 00:00:00", tz="UTC") + jitter(1:10) * 10
pc(x, regularise_coord(x))
x <- as.POSIXct("2010-01-01 00:00:00", tz="UTC") + jitter(1:10) * 3600 * 24
pc(x, regularise_coord(x))
# Dates
set.seed(1)
x <- as.Date("2010-01-01") + round(jitter(1:10)*20)
pc(x, regularise_coord(x))
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.