Learn R Programming

funData (version 1.2)

ggplot.multiFunData: Visualize multivariate functional data objects using ggplot

Description

This function allows to plot multiFunData objects based on the ggplot2 package. The function applies the ggplot.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.

Usage

ggplot.multiFunData(data, obs = 1:nObs(data), dim = 1:length(data),
  plotGrid = FALSE, ...)

# S4 method for multiFunData ggplot(data, ...)

Arguments

data

A multiFunData object that is to be plotted.

obs

A vector of numerics giving the observations to plot. Defaults to all observations in data. For two-dimensional functions (images) obs must have length 1.

dim

The dimensions to plot. Defaults to length(data), i.e. all functions in data 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 ggplot functions for funData objects.

Value

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.

See Also

'>multiFunData, ggplot, plot.multiFunData

Examples

Run this code
# NOT RUN {
# Install packages ggplot2 and gridExtra before running the examples
# }
# NOT RUN {
# One-dimensional elements
argvals <- 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 <- ggplot(m1) # default
g[[1]] # plot first element
g[[2]] # plot second element
gridExtra::grid.arrange(grobs = g, nrow = 1) # requires gridExtra package

ggplot(m1, plotGrid = TRUE) # the same directly with plotGrid = TRUE

# }
# NOT RUN {
# Mixed-dimensional elements
X <- 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)

ggplot(m2, obs = 1, plotGrid = TRUE)

# Customizing plots (see ggplot2 documentation for more details)
g2 <- ggplot(m2, obs = 1)
g2[[1]] <- g2[[1]] + ggplot2::ggtitle("First element") + ggplot2::theme_bw()
g2[[2]] <- g2[[2]] + ggplot2::ggtitle("Second element") + 
                     ggplot2::scale_fill_gradient(high = "green", low = "blue")
gridExtra::grid.arrange(grobs = g2, nrow = 1) # requires gridExtra package
# }

Run the code above in your browser using DataLab