Visualize multivariate functional data objects using ggplot
Visualize multivariate functional data objects using ggplot
This function allows to plot multiFunData objects based on the ggplot2 package. The function applies the autoplot.funData function to each element and returns either a combined plot with all elements plotted in one row or a list containing the different subplots as ggplot objects. The individual objects can be customized using all functionalities of the ggplot2 package.
autoplot.multiFunData( object, obs = seq_len(nObs(object)), dim = seq_len(length(object)), plotGrid =FALSE,...)
Arguments
object: A multiFunData object that is to be plotted.
obs: A vector of numerics giving the observations to plot. Defaults to all observations in object. For two-dimensional functions (images) obs must have length 1.
dim: The dimensions to plot. Defaults to length(object), i.e. all functions in object are plotted.
plotGrid: Logical. If TRUE, the data is plotted using grid.arrange and the list of ggplot objects is returned invisibly. If FALSE, only the list of objects is returned. Defaults to FALSE.
...: Further parameters passed to the univariate autoplot.funData functions for funData objects.
Returns
A list of ggplot objects that are also printed directly as a grid if plotGrid = TRUE.
Warning
Currently, the function does not accept different parameters for the univariate elements.
Examples
# Load packages ggplot2 and gridExtra before running the exampleslibrary("ggplot2"); library("gridExtra")# One-dimensional elementsargvals <- seq(0,2*pi,0.01)f1 <- funData(argvals, outer(seq(0.75,1.25, length.out =11), sin(argvals)))f2 <- funData(argvals, outer(seq(0.75,1.25, length.out =11), cos(argvals)))m1 <- multiFunData(f1, f2)g <- autoplot(m1)# defaultg[[1]]# plot first elementg[[2]]# plot second elementgridExtra::grid.arrange(grobs = g, nrow =1)# requires gridExtra packageautoplot(m1, plotGrid =TRUE)# the same directly with plotGrid = TRUE# Mixed-dimensional elementsX <- array(0, dim = c(11, length(argvals), length(argvals)))X[1,,]<- outer(argvals, argvals,function(x,y){sin((x-pi)^2+(y-pi)^2)})f2 <- funData(list(argvals, argvals), X)m2 <- multiFunData(f1, f2)autoplot(m2, obs =1, plotGrid =TRUE)# Customizing plots (see ggplot2 documentation for more details)g2 <- autoplot(m2, obs =1)g2[[1]]<- g2[[1]]+ ggtitle("First element")+ theme_bw()g2[[2]]<- g2[[2]]+ ggtitle("Second element")+ scale_fill_gradient(high ="green", low ="blue")gridExtra::grid.arrange(grobs = g2, nrow =1)# requires gridExtra package