Some base and ggplot-functions for displaying functional data in spaghetti- (i.e., line plots) and lasagna- (i.e., heat map) flavors.

funplot(
  f,
  arg,
  n_grid = 50,
  points = is_irreg(f),
  type = c("spaghetti", "lasagna"),
  alpha = min(1, max(0.05, 2/length(f)))
)

# S3 method for tf
plot(
  x,
  y,
  n_grid = 50,
  points = is_irreg(x),
  type = c("spaghetti", "lasagna"),
  alpha = min(1, max(0.05, 2/length(x))),
  ...
)

# S3 method for tf
lines(x, arg, n_grid = 50, alpha = min(1, max(0.05, 2/length(x))), ...)

# S3 method for tf
points(
  x,
  arg,
  n_grid = NA,
  alpha = min(1, max(0.05, 2/length(x))),
  interpolate = FALSE,
  ...
)

Arguments

f

an tf object

arg

(optional) numeric vector to be used as arg. See details.

n_grid

minimal size of equidistant grid used for plotting, defaults to 50. See details.

points

should the original evaluation points be marked by points? Defaults to TRUE for irregular tfd and FALSE for all others

type

"spaghetti": line plots, "lasagna": heat maps.

alpha

alpha-value (seegrDevices::rgb()) for noodle transparency. Defaults to 2/(no. of observations). Lower is more transparent.

x

an tf object

y

(optional) numeric vector to be used as arg (i.e., for the x-axis...!)

...

additional arguments for matplot() ("spaghetti") or image() ("lasagna")

interpolate

should functions be evaluated (i.e., inter-/extrapolated) for arg for which no original data is available? Only relevant for tfd, defaults to FALSE

Value

for funplot: the ggplot-object for further modification. For the others: the plotted tf-object, invisibly.

Details

funplot uses ggplot2, the others use the base-system.

If no arg are provided, evaluation points (arg) for the functions are given by the union of the tf's arg and an equidistant grid over its domain with n_grid points. If you want to only see the original data for tfd-objects without inter-/extrapolation, use n_grid < 1 or n_grid = NA.

References

Swihart, B. J., Caffo, B., James, B. D., Strand, M., Schwartz, B. S., & Punjabi, N. M. (2010). Lasagna plots: a saucy alternative to spaghetti plots. Epidemiology (Cambridge, Mass.), 21(5), 621-625.