This function plots observations of univariate functional data on their domain.
## S3 method for class 'funData'plot( x, y, obs = seq_len(nObs(x)), type ="l", lty =1, lwd =1, col =NULL, xlab ="argvals", ylab ="", legend =TRUE, plotNA =FALSE, add =FALSE,...)## S4 method for signature 'funData,missing'plot(x, y,...)
Arguments
x: An object of class funData.
y: Missing.
obs: A vector of numerics giving the observations to plot. Defaults to all observations in x. For two-dimensional functions (images) obs must have length 1.
type: The type of plot. Defaults to "l" (line plot). See plot for details.
lty: The line type. Defaults to 1 (solid line). See par for details.
lwd: The line width. Defaults to 1. See par for details.
col: The color of the functions. If not supplied (NULL, default value), one-dimensional functions are plotted in the rainbow palette and two-dimensional functions are plotted using tim.colors from package fields-package.
xlab, ylab: The titles for x- and y-axis. Defaults to "argvals"
for the x-axis and no title for the y-axis. See plot for details.
legend: Logical. If TRUE, a color legend is plotted for two-dimensional functions (images). Defaults to TRUE.
plotNA: Logical. If TRUE, missing values are interpolated using the approxNA function (only for one-dimensional functions). Defaults to FALSE.
add: Logical. If TRUE, add to current plot (only for one-dimensional functions). Defaults to FALSE.
...: Additional arguments to matplot
(one-dimensional functions) or image.plot/ image (two-dimensional functions).
Details
If some observations contain missing values (coded via NA), the functions can be interpolated using the option plotNA = TRUE. This option relies on the na.approx function in package zoo and is currently implemented for one-dimensional functions only in the function approxNA.
Warning
The function is currently implemented only for functional data with one- and two-dimensional domains.
Examples
oldpar <- par(no.readonly =TRUE)# One-dimensionalargvals <- seq(0,2*pi,0.01)object <- funData(argvals, outer(seq(0.75,1.25, length.out =11), sin(argvals)))plot(object, main ="One-dimensional functional data")# Two-dimensionalX <- array(0, dim = c(2, length(argvals), length(argvals)))X[1,,]<- outer(argvals, argvals,function(x,y){sin((x-pi)^2+(y-pi)^2)})X[2,,]<- outer(argvals, argvals,function(x,y){sin(2*x*pi)* cos(2*y*pi)})object2D <- funData(list(argvals, argvals), X)plot(object2D, main ="Two-dimensional functional data (obs 1)", obs =1)plot(object2D, main ="Two-dimensional functional data (obs 2)", obs =2)## Not run: plot(object2D, main = "Two-dimensional functional data")# must specify obs!### More examples ###par(mfrow = c(1,1))# using plotNAif(requireNamespace("zoo", quietly =TRUE)){objectMissing <- funData(1:5, rbind(c(1,NA,5,4,3), c(10,9,NA,NA,6)))par(mfrow = c(1,2))plot(objectMissing, type ="b", pch =20, main ="plotNA = FALSE")# the defaultplot(objectMissing, type ="b", pch =20, plotNA =TRUE, main ="plotNA = TRUE")# requires zoo}# Changing colorsplot(object, main ="1D functional data in grey", col ="grey")plot(object, main ="1D functional data in heat.colors", col = heat.colors(nObs(object)))plot(object2D, main ="2D functional data in topo.colors", obs =1, col = topo.colors(64))par(oldpar)