plotSmoothsComparison {growthPheno}R Documentation

Plots several sets of smoothed values for a response, possibly along with growth rates and optionally including the unsmoothed values, as well as deviations boxplots.

Description

Plots the smoothed values for an observed response and, optionally, the unsmoothed observed response using plotProfiles. Depending on the setting of trait.types (response, AGR or RGR), the computed traits of the Absolute Growth Rates (AGR) and/or the Relative Growth Rates (RGR) are plotted. This function will also calculate and produce, using plotDeviationsBoxes, boxplots of the deviations of the supplied smoothed values from the observed response values for the traits and for combinations of the different smoothing parameters and for subsets of non-smoothing-factor combinations. The observed and smoothed values are supplied in long format i.e. with the values for each set of smoothing parameters stacked one under the other in the supplied smooths.frame. Such data can be generated using probeSmooths; to prevent probeSmooths producing the plots, which it is does using plotSmoothsComparison, plotDeviationsBoxes and plotSmoothsMedianDevns, set which.plots to none. The smoothing parameters include spline.types, df, lambdas and smoothing.methods (see probeSmooths).

Multiple plots, possibly each having multiple facets, are produced using ggplot2. The layout of these plots is controlled via the arguments plots.by, facet.x and facet.y. The basic principle is that the number of levels combinations of the smoothing-parameter factors Type, TunePar, TuneVal, Tuning (the combination of (TunePar and TuneVal), and Method that are included in plots.by, facet.x and facet.y must be the same as those covered by the combinations of the values supplied to spline.types, df, lambdas and Method and incorporated into the smooths.frame input to plotSmoothsComparison via the data argument. This ensures that smooths from different parameter sets are not pooled into the same plot. The factors other than the smoothing-parameter factors can be supplied to the plots.by and facet arguments.

The following profiles plots can be produced: (i) separate plots of the smoothed traits for each combination of the smoothing parameters (include Type, Tuning and Method in plots.by); (ii) as for (i), with the corresponding plot for the unsmoothed trait preceeding the plots for the smoothed trait (also set include.raw to alone); (iii) profiles plots that compare a smoothed trait for all combinations of the values of the smoothing parameters, arranging the plots side-by-side or one above the other (include Type, Tuning and Method in facet.x and/or facet.y - to include the unsmoothed trait set include.raw to one of facet.x or facet.y; (iv) as for (iii), except that separate plots are produced for each combination of the levels of the factors in plot.by and each plot compares the smoothed traits for the smoothing-parameter factors included in facet.x and/or facet.y (set both plots.by and one or more of facet.x and facet.y).

Usage

plotSmoothsComparison(data, response, response.smoothed = NULL, 
                      individuals = "Snapshot.ID.Tag", times = "DAP", 
                      trait.types = c("response", "AGR", "RGR"), 
                      x.title = NULL, y.titles = NULL, 
                      profile.plot.args = 
                        args4profile_plot(plots.by = NULL, 
                                          facet.x = ".", facet.y = ".", 
                                          include.raw = "no"),
                      printPlot = TRUE, ...)

Arguments

data

A smooths.frame, such as is produced by probeSmooths and that contains the data resulting from smoothing a response over time for a set of individuals, the data being arranged in long format both with respect to the times and the smoothing-parameter values used in the smoothing. That is, each response occupies a single column. The unsmoothed response and the response.smoothed are to be plotted for different sets of values for the smoothing parameters. The smooths.frame must include the columns Type, TunePar, TuneVal, Tuning and Method, and the columns nominated using the arguments individuals, times, plots.by, facet.x, facet.y, response, response.smoothed, and, if requested, the AGR and the RGR of the response and response.smoothed. The names of the growth rates should be formed from response and response.smoothed by adding .AGR and .RGR to both of them.

response

A character specifying the response variable for which the observed values are supplied.

response.smoothed

A character specifying the name of the column containing the values of the smoothed response variable, corresponding to response and obtained for the combinations of smoothing.methods and df, usually using smoothing splines. If response.smoothed is NULL, then response.smoothed is set to the response to which is added the prefix s.

times

A character giving the name of the column in data containing the times at which the data was collected, either as a numeric, factor, or character. It will be used to provide the values to be plotted on the x-axis. If a factor or character, the values should be numerics stored as characters.

individuals

A character giving the name of the factor that defines the subsets of the data for which each subset corresponds to the response values for an individual (e.g. plant, pot, cart, plot or unit).

trait.types

A character giving the trait.types that are to be plotted when which.plots is profiles. Irrespective of the setting of get.rates, the nominated traits are plotted. If all, each of response, AGR and RGR is plotted.

x.title

Title for the x-axis, used for all plots. If NULL then set to times.

y.titles

A character giving the titles for the y-axis, one for each trait specified by trait.types and used for all plots. If NULL, then set to the traits derived for response from trait.types.

profile.plot.args

A named list that is most easily generated using args4profile_plot, it documenting the options available for varying profile plots and boxplots. Note that if args4profile_plot is to be called to change from the default settings given in the default plotSmoothsComparison call and some of those settings are to be retained, then the arguments whose settings are to be retained must also be included in the call to args4profile_plot; be aware that if you call args4profile_plot, then the defaults for this call are those for args4profile_plot, NOT the call to args4profile_plot shown as the default for plotSmoothsComparison.

printPlot

A logical indicating whether or not to print any plots.

...

allows passing of arguments to plotProfiles.

Value

A multilevel list that contains the ggplot objects for the plots produced. The first-level list has a component for each trait.types and each of these is a second-level list that contains the trait profile plots and for a trait. It may contain components labelled Unsmoothed, all or for one of the levels of the factors in plots.by; each of these third-level ists contains a ggplot object that can be plotted using print.

Author(s)

Chris Brien

See Also

traitSmooth, probeSmooths, args4profile_plot, plotDeviationsBoxes, plotSmoothsMedianDevns, ggplot2.

Examples

data(exampleData)
vline <- list(ggplot2::geom_vline(xintercept=29, linetype="longdash", size=1))
traits <- probeSmooths(data = longi.dat, 
                       response = "PSA", response.smoothed = "sPSA", 
                       times = "DAP", 
                       #only df is changed from the probeSmooth default
                       smoothing.args = 
                         args4smoothing(smoothing.methods = "direct", 
                                        spline.types = "NCSS", 
                                        df = c(4,7), lambdas = NULL), 
                       which.plots = "none")
plotSmoothsComparison(data = traits, 
                      response = "PSA", response.smoothed = "sPSA", 
                      times = "DAP", x.title = "DAP",
                      #only facet.x is changed from the probeSmooth default
                      profile.plot.args = 
                        args4profile_plot(plots.by = NULL, 
                                          facet.x = "Tuning", facet.y = ".", 
                                          include.raw = "no", 
                                          ggplotFuncs = vline))

[Package growthPheno version 2.1.25 Index]