Learn R Programming

funData (version 1.1)

ggplot.irregFunData: Visualize irregular functional data objects using ggplot

Description

This function allows to plot irregFunData objects on their domain based on the ggplot2 package. The function provides a wrapper that rearranges the data in a irregFunData object returns a basic ggplot object, which can be customized using all functionalities of the ggplot2 package.

Usage

ggplot.irregFunData(data, obs = 1:nObs(data), geom = "line", add = FALSE,
  ...)

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

Arguments

data

A irregFunData object.

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.

geom

A character string describing the geometric object to use. Defaults to "line". See ggplot2 for details.

add

Logical. If TRUE, add to current plot (only for one-dimensional functions). Defaults to FALSE.

...

Further parameters passed to stat_identity, e.g. alpha, color, fill, linetype, size).

Value

A ggplot object that can be customized using all functionalities of the ggplot2 package.

See Also

, ggplot, plot.irregFunData

Examples

Run this code
# Install packages ggplot2 and gridExtra before running the examples


# Generate data
argvals <- seq(0,2*pi,0.01)
ind <- replicate(5, sort(sample(1:length(argvals), sample(5:10,1))))
object <- irregFunData(argvals = lapply(ind, function(i){argvals[i]}),
                  X = lapply(ind, function(i){sample(1:10,1) / 10 * argvals[i]^2}))

# Plot the data
ggplot(object)

 # Parameters passed to geom_line are passed via the ... argument
ggplot(object, color = "red", linetype = 3)

# Plot the data and add green dots for the 2nd function
ggplot(object) + ggplot(object, obs = 2, geom = "point", color = "green", add = TRUE)

# New layers can be added directly to the ggplot object using functions from the ggplot2 package
g <- ggplot(object)
g + ggplot2::theme_bw() + ggplot2::ggtitle("Plot with minimal theme and axis labels") +
    ggplot2::xlab("The x-Axis") + ggplot2::ylab("The y-Axis")

Run the code above in your browser using DataLab