Wrapper function which interpolates 3D data. Designed for oceanographic section plots.

interpolate_section(
  df = NULL,
  x,
  y,
  z,
  method = "linear",
  format = "ggplot",
  nx = 100,
  ny = 100,
  scale_distances = FALSE,
  log_y = FALSE,
  extrapolate = FALSE,
  na.rm = TRUE,
  return_df_names = FALSE
)

Arguments

df

data frame. Can be NULL if x, y, z are given as numeric vectors

x, y, z

coordinates as numeric vectors, if df = NULL. Otherwise characters specifying the column names of the coodrinates in df. The interpolation will be done as f(x, y) ~ z

method

Character specifying the interpolation method. Options: "linear", "spline", "mba", and "idw"

format

Character specifying the output format. Options: "ggplot" (for plotting with ggplot2), "image" (for plotting with the image function) or "wide" for exporting as a wide data frame.

nx, ny

Integer giving the dimensions for the output

scale_distances

Logical indicating whether x and y should be scaled to equal distances. May be useful when interpolating variables that have different units or distances.

log_y

logical indicating whether y axis should be interpolated using log10(y + 1) scale.

extrapolate

logical indicating whether the interpolation function should be allowed to extrapolate beyond initial data.

na.rm

logical indicating whether rows containing NA values should be omited from df or x, y, z. NA values are not permitted in most of the interpolation methods. See sectionGrid for one way of interpolating NA values away from the input dataset.

return_df_names

logical indicating whether the original column names should be returned instead of x, y, and z if df != NULL

Value

Returns a data.frame with interpolated x,y,z coordinates.

Details

This is a wrapper function which uses existing interpolation solutions. Following interpolation methods have been implemented:

  • "linear" for linear interpolation using the interp function with linear = TRUE.

  • "spline" for spline interpolation using the interp function with linear = FALSE.

  • "mba" for multilevel B-spline interpolation using the mba.surf function. Appears to produce the best looking results. Recommended.

  • "idw" for inverse distance weighted interpolation using the idw function. This function was originally developed for spatial data where x- and y axes are given in the same units and have similar effect on the result. While it would, no doubt, be possible to account section design in the model specification, this has not been done in the interpolate_section function. Therefore, using this option is not recommended.