Description Usage Arguments Details Value Functions Examples
These functions are both a thin wrappers around the approx() function from
Base R's stats package. The primary difference is that these functions
output a tibble instead of list with x and y components. The
tibble / data frame output simplifies use in some work flows.
1 2 3 4 5 6 7 8 9 10 11 |
.x |
Vector of (observed) x, or independent values |
.y |
Vector of (observed) y, or dependent values |
.grid |
Vector of locations for calculated interpolated values. |
.name |
An identifier added to the output dataframe, often useful
when this function is used in loops or with |
grow_grid |
Should the output grid be extended to whole integer values
just above and just below the observed data ( |
... |
Further parameters to send to |
.res |
Single numeric value representing output resolution in
units compatible with the |
with_zero |
Should the grid be expanded to include a value of zero? Useful for interpolation along depths, in the common situation where the shallowest observation is slightly below the surface, but a nice graphic should start at depth == 0. |
The functions uses simple linear interpolation to estimate values at (generally unmeasured) locations between observed points.
The parameter names .y, .x, are mnemonics, to remind you that
the function will estimate the dependent variable .y at evenly spaced
intervals values along the .x direction, based on the (.x, .y) pairs
provided.
Ideas for this function and its use in profile graphics were inspired by Dewey Dunnington's fishandwhistle.net blog.
A data frame with components id (arbitrary identifier, often useful
when output from these functions are fed directly into loops or used in
functional programming.), ind (independent variable), and dep (dependent
variable).
interpol: Interpolate to values of a grid provided nu the user.
interpol() does nothing but check arguments, set useful defaults and
convert the output of approx() to a tibble.
interpol_res: Interpolation based on resolution.
interpol_res() is specialized for creating interpolated values at
regularly spaced intervals. It includes some optional parameters that
simplify its use in the context of creating smoothed depth-time plots from
repeated "profile" data, as often collected in limnology and oceanography.
The function is not directly used by other functions in this package, which
al lrely on interpol() instead.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | data(dep_sonde)
dat <- dep_sonde[dep_sonde$month == 'Jul',]
grid <- seq(0, 14, 1)
interp <- interpol(dat$depth, dat$temp, .grid = grid)
ggplot(dat, aes(temp, depth)) +
geom_point(size = 3, col = 'red') +
geom_point(mapping = aes(dep, ind), data = interp, shape = 3) +
scale_y_reverse()
data(dep_sonde)
dat <- dep_sonde[dep_sonde$month == 'Jul',]
interp <- interpol_res(dat$depth, dat$temp, .res = 0.5)
ggplot(dat, aes(temp, depth)) +
geom_point(size = 3, col = 'red') +
geom_point(mapping = aes(dep, ind), data = interp, shape = 3) +
scale_y_reverse()
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.