#' Add multiple functions to GRF object
#'
#' Generates multiple functions from the GRF object specified as a parameter, and adds them to the object.
#' See \code{\link{add.grf.function}} for details.
#'
#' @param grf.object A GRF object generated by \code{\link{generate.grf.object}}.
#' @param num.functions The number of functions to be added.
#' @param function.names A character vector specifying the names used for each function.
#' @param seed Optional. Must be a numeric vector of length \code{num.functions} (or \code{length(function.names)}).
#'
#' @details Either \code{num.functions} or \code{function.names} must be specified.
#'
#' @return The GRF object with the functions added to the \code{functions} list.
#'
#' @examples
#' library(GRFics)
#' # Prepare GRF object
#' grf.object = generate.grf.object(0, 1, 0, 1, 100, 100)
#' # Add two functions to object
#' grf.object = add.multiple.grf.functions(grf.object, function.names = c("u", "v"))
#' # Extract data frames
#' function.1.df = get.function.df(grf.object, function.name = "u")
#' function.2.df = get.function.df(grf.object, function.number = 2)
#' # Create combined data frame for plotting
#' combined.df = rbind(function.1.df, function.2.df)
#' combined.df$facet.var = rep(1:2, each = nrow(function.1.df))
#' # Plot functions side by side
#' library(ggplot2)
#' ggplot()+
#' geom_raster(data = combined.df, aes(x = x, y = y, fill = z))+
#' coord_fixed()+
#' facet_grid(cols = vars(facet.var))
#'
#' @export
#' @author Mathias Isaksen \email{mathiasleanderi@@gmail.com}
add.multiple.grf.functions = function(grf.object, num.functions = NULL, function.names = NULL, seed = NULL) {
if (is.null(num.functions)) {
if (!is.null(function.names)) {
num.functions = length(function.names)
} else {
stop("Both num.functions and function.names is missing.")
}
}
for (i in 1:num.functions) {
grf.object = add.grf.function(grf.object, function.name = function.names[i], seed = seed[i])
}
return(grf.object)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.