diff --git a/CRAN-SUBMISSION b/CRAN-SUBMISSION index 07d2dcf..493e1d9 100644 --- a/CRAN-SUBMISSION +++ b/CRAN-SUBMISSION @@ -1,3 +1,3 @@ -Version: 1.2.0 -Date: 2024-05-31 09:46:32 UTC -SHA: ebce045fe222badd826f94e2d7cabb4475a5f32d +Version: 1.2.1 +Date: 2024-06-04 09:02:24 UTC +SHA: ec8d469ab6c9f36ffdcb8e3c7b1bab045d6ccef6 diff --git a/DESCRIPTION b/DESCRIPTION index 6666c94..950036e 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Type: Package Package: biometryassist Title: Functions to Assist Design and Analysis of Agronomic Experiments -Version: 1.2.0 +Version: 1.2.1 Authors@R: c(person(given = "Sharon", family = "Nielsen", diff --git a/NAMESPACE b/NAMESPACE index 9a293dd..7194e19 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -87,6 +87,7 @@ importFrom(stats,var) importFrom(stringi,stri_sort) importFrom(stringi,stri_split_fixed) importFrom(utils,available.packages) +importFrom(utils,compareVersion) importFrom(utils,download.file) importFrom(utils,install.packages) importFrom(utils,installed.packages) diff --git a/NEWS.md b/NEWS.md index b8a10c3..199592f 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,8 +1,14 @@ +# biometryassist 1.2.1 + +## Bug Fixes + +- The new `summary_graph()` function was accidentally left out of the CRAN submission. + # biometryassist 1.2.0 ## Major changes -- Introduced the `summary_plot()` (#75) and `heat_map()` (#19) functions +- Introduced the `summary_graph()` (#75) and `heat_map()` (#19) functions - Enabled arbitrary `row`, `column`, `block` and `treatment` columns to be provided in the `autoplot.design()` function, to enable more general plotting of designs. (#28) ## Minor changes diff --git a/R/autoplot.R b/R/autoplot.R index 606119c..396e942 100644 --- a/R/autoplot.R +++ b/R/autoplot.R @@ -1,4 +1,4 @@ -#' Automatic plots for objects generated in biometryassist +#' Generate automatic plots for objects generated in biometryassist #' #' @param object An object to create a plot for. Currently objects from the [multiple_comparisons()] or [design()] functions with class "mct" or "design" respectively are supported. #' @param label_height Height of the text labels above the upper error bar on the plot. Default is 0.1 (10%) of the difference between upper and lower error bars above the top error bar. Values > 1 are interpreted as the actual value above the upper error bar. diff --git a/R/des_info.R b/R/des_info.R index e3f2b2e..362ac6e 100644 --- a/R/des_info.R +++ b/R/des_info.R @@ -1,4 +1,4 @@ -#' Produces graph of design layout, skeletal ANOVA table and data frame with complete design +#' Produce a graph of design layout, skeletal ANOVA table and data frame with complete design #' #' @param design.obj An `agricolae` design object. #' @param nrows The number of rows in the design. @@ -11,7 +11,7 @@ #' @param plot Logical (default `TRUE`). If `TRUE`, display a plot of the generated design. A plot can always be produced later using [autoplot()]. #' @param rotation Rotate the text output as Treatments within the plot. Allows for easier reading of long treatment labels. Takes positive and negative values being number of degrees of rotation from horizontal. #' @param size Increase or decrease the text size within the plot for treatment labels. Numeric with default value of 4. -#' @param margin Logical (default FALSE). Expand the plot to the edges of the plotting area i.e. remove white space between plot and axes. +#' @param margin Logical (default FALSE). Setting to `TRUE` will add a margin (white space) between plot and axes. #' @param save One of `FALSE` (default)/`"none"`, `TRUE`/`"both"`, `"plot"` or `"workbook"`. Specifies which output to save. #' @param savename A filename for the design to be saved to. Default is the type of the design combined with "_design". #' @param plottype The type of file to save the plot as. Usually one of `"pdf"`, `"png"`, or `"jpg"`. See [ggplot2::ggsave()] for all possible options. diff --git a/R/design.R b/R/design.R index b1aad1f..ce1ff63 100644 --- a/R/design.R +++ b/R/design.R @@ -1,14 +1,14 @@ -#' Produces an experimental design with graph of design layout and skeletal ANOVA table +#' Create a complete experimental design with graph of design layout and skeletal ANOVA table #' -#' @param type The type of design. Supported design types are `crd`, `rcbd`, `lsd`, `crossed:` where `` is one of the previous types and `split`. See Details for more information. +#' @param type The type of design. Supported design types are `crd`, `rcbd`, `lsd`, `crossed:` where `` is one of the previous types, and `split`. See Details for more information. #' @param treatments A vector containing the treatment names or labels. -#' @param reps The number of replicates. Not required for Latin Squared Designs. +#' @param reps The number of replicates. Ignored for Latin Square Designs. #' @param nrows The number of rows in the design. #' @param ncols The number of columns in the design. #' @param brows For RCBD and Split Plot designs. The number of rows in a block. #' @param bcols For RCBD and Split Plot designs. The number of columns in a block. #' @param byrow For split-plot only. Logical (default `TRUE`). Provides a way to arrange plots within whole-plots when there are multiple possible arrangements. -#' @param sub_treatments A vector of treatments for subplots in a split plot design. +#' @param sub_treatments A vector of treatments for sub-plots in a split plot design. #' @param fac.names Allows renaming of the `A` level of factorial designs (i.e. those using [agricolae::design.ab()]) by passing (optionally named) vectors of new labels to be applied to the factors within a list. See examples and details for more information. #' @param fac.sep The separator used by `fac.names`. Used to combine factorial design levels. If a vector of 2 levels is supplied, the first separates factor levels and label, and the second separates the different factors. #' @param plot Logical (default `TRUE`). If `TRUE`, display a plot of the generated design. A plot can always be produced later using [autoplot()]. @@ -16,7 +16,7 @@ #' @param size Increase or decrease the text size within the plot for treatment labels. Numeric with default value of 4. #' @param margin Logical (default `FALSE`). Expand the plot to the edges of the plotting area i.e. remove white space between plot and axes. #' @param save One of `FALSE` (default)/`"none"`, `TRUE`/`"both"`, `"plot"` or `"workbook"`. Specifies which output to save. -#' @param savename A filename for the design to be saved to. Default is the type of the design combined with "_design". +#' @param savename A file name for the design to be saved to. Default is the type of the design combined with "_design". #' @param plottype The type of file to save the plot as. Usually one of `"pdf"`, `"png"`, or `"jpg"`. See [ggplot2::ggsave()] for all possible options. #' @param seed Logical (default `TRUE`). If `TRUE`, return the seed used to generate the design. If a numeric value, use that value as the seed for the design. #' @param quiet Logical (default `FALSE`). Hide the output. @@ -25,7 +25,7 @@ #' @details The designs currently supported by `type` are Completely Randomised designs (`crd`), Randomised Complete Block designs (`rcbd`), Latin Square Designs (`lsd`), Factorial with crossed structure (use `crossed:` where `` is one of the previous types e.g. `crossed:crd`) and Split Plot designs (`split`). Nested factorial designs are supported through manual setup, see Examples. #' @details If `save = TRUE` (or `"both"`), both the plot and the workbook will be saved to the current working directory, with filename given by `savename`. If one of either `"plot"` or `"workbook"` is specified, only that output is saved. If `save = FALSE` (the default, or equivalently `"none"`), nothing will be output. #' @details `fac.names` can be supplied to provide more intuitive names for factors and their levels in factorial and split plot designs. They can be specified in a list format, for example `fac.names = list(A_names = c("a", "b", "c"), B_names = c("x", "y", "z"))`. This will result a design output with a column named `A_names` with levels `a, b, c` and another named `B_names` with levels `x, y, z`. Labels can also be supplied as a character vector (e.g. `c("A", "B")`) which will result in only the treatment column names being renamed. Only the first two elements of the list will be used, except in the case of a 3-way factorial design. -#' @details `...` allows extra arguments to be passed to ggsave for output of the plot. The details of possible arguments can be found in [ggplot2::ggsave()]. +#' @details `...` allows extra arguments to be passed to `ggsave()` for output of the plot. The details of possible arguments can be found in [ggplot2::ggsave()]. #' #' @importFrom graphics plot #' @importFrom ggplot2 ggsave diff --git a/R/heatmap.R b/R/heatmap.R index 897fe71..74965f8 100644 --- a/R/heatmap.R +++ b/R/heatmap.R @@ -1,15 +1,16 @@ -#' Heatmap +#' Produce a heatmap of variables in a grid layout. #' -#' Function to plot heatmaps of variables in a grid layout. +#' This function plots a heatmap of variables in a grid layout, optionally grouping them. #' -#' @param data A data frame containing the data to be plotted -#' @param value A column of `data`, containing the values that vary over the space which produces the colours +#' @param data A data frame containing the data to be plotted. +#' @param value A column of `data`, containing the values that vary over the space which produces the colours. #' @param x_axis The column of `data` to use as the x axis data. #' @param y_axis The column of `data` to use as the y axis data. #' @param grouping An optional grouping variable to facet the plot by. #' @param raster Logical (default: `TRUE`). If `TRUE` uses [ggplot2::geom_raster()] for speed. Will not work if the grid is irregular. -#' @param smooth Logical (default: `TRUE`). If `raster` is `TRUE`, interpolation can be applied across the grid to obtain a smoothed grid. Ignored if `raster` is `FALSE`. -#' @param palette Colour palatte to use. By default it will use the `viridis` (colour-blind friendly) palette. Other palettes available can be seen with [grDevices::hcl.pals()]. +#' @param smooth Logical (default: `FALSE`). If `raster` is `TRUE`, interpolation can be applied across the grid to obtain a smoothed grid. Ignored if `raster` is `FALSE`. +#' @param palette Colour palette to use. By default it will use the `viridis` (colour-blind friendly) palette. Other palettes available can be seen with [grDevices::hcl.pals()]. +#' @param ... Other arguments passed to [`facet_wrap()`] #' #' @importFrom ggplot2 ggplot aes geom_tile geom_raster scale_fill_gradientn scale_x_continuous scale_y_continuous facet_wrap vars theme_bw #' @importFrom rlang ensym enquo quo_is_null @@ -25,11 +26,26 @@ #' dat$groups <- sample(rep(LETTERS[1:6], times = 5)) #' #' heat_map(dat, value, x, y) +#' +#' # Column names can be quoted, but don't need to be. #' heat_map(dat, "value", "x", "y", "groups") -heat_map <- function(data, value, x_axis, y_axis, grouping = NULL, raster = TRUE, smooth = FALSE, palette = "default") { +#' +#' # Different palettes are available +#' heat_map(dat, value, x, y, palette = "Spectral") +#' +#' # Arguments in ... are passed through to facet_wrap +#' heat_map(dat, value, x, y, groups, labeller = ggplot2:::label_both) +#' heat_map(dat, value, x, y, groups, scales = "free_y") +#' heat_map(dat, value, x, y, groups, nrow = 1) +heat_map <- function(data, value, x_axis, y_axis, grouping = NULL, raster = TRUE, smooth = FALSE, palette = "default", ...) { # TODO: # - Error and sanity checking + if(!is.data.frame(data)) { + stop(data, " is not a data frame.", call. = FALSE) + } + + rlang::check_dots_used() value <- rlang::ensym(value) x_axis <- rlang::ensym(x_axis) @@ -58,7 +74,7 @@ heat_map <- function(data, value, x_axis, y_axis, grouping = NULL, raster = TRUE if(!rlang::quo_is_null(grouping)) { grouping <- rlang::ensym(grouping) - plt <- plt + ggplot2::facet_wrap(ggplot2::vars({{ grouping }})) + plt <- plt + ggplot2::facet_wrap(ggplot2::vars({{ grouping }}), ...) } plt <- plt+ggplot2::theme_bw() diff --git a/R/install_asreml.R b/R/install_asreml.R index ae9ed4a..710d556 100644 --- a/R/install_asreml.R +++ b/R/install_asreml.R @@ -1,4 +1,4 @@ -#' Install or Update the ASReml-R package +#' Install or update the ASReml-R package #' #' @description Helper functions for installing or updating the ASReml-R package, intended to reduce the difficulty of finding the correct version for your operating system and R version. #' diff --git a/R/logltest.R b/R/logltest.R index a1629ee..9042191 100644 --- a/R/logltest.R +++ b/R/logltest.R @@ -1,4 +1,4 @@ -#' Log-likelihood test for comparing terms in ASReml-R models +#' Conduct a log-likelihood test for comparing terms in ASReml-R models #' #' @param model.obj An ASReml-R model object #' @param rand.terms Random terms from the model. Default is NULL. diff --git a/R/mct.R b/R/mct.R index f92716e..4b8a7c1 100644 --- a/R/mct.R +++ b/R/mct.R @@ -1,4 +1,4 @@ -#' Multiple Comparison Tests +#' Perform Multiple Comparison Tests on a statistical model #' #' A function for comparing and ranking predicted means with Tukey's Honest Significant Difference (HSD) Test. #' @@ -484,7 +484,7 @@ multiple_comparisons <- function(model.obj, } -#' Print method for multiple_comparisons +#' Print output of multiple_comparisons #' #' @param x An mct object to print to the console. #' @param ... Other arguments diff --git a/R/resplot.R b/R/resplot.R index 4fd1a9a..f4671c4 100644 --- a/R/resplot.R +++ b/R/resplot.R @@ -1,4 +1,4 @@ -#' Residual plots of linear models. +#' Produce residual plots of linear models #' #' Produces plots of residuals for assumption checking of linear (mixed) models. #' @@ -10,7 +10,7 @@ #' @param call.size A numeric value for the size of the model displayed on the plot. #' @param mod.obj Deprecated to be consistent with other functions. Please use `model.obj` instead. #' -#' @return A list containing ggplot2 objects which are diagnostic plots. +#' @return A ggplot2 object containing the diagnostic plots. #' #' @importFrom ggplot2 ggplot geom_histogram aes theme_bw stat_qq labs geom_qq_line geom_point #' @importFrom stats fitted qnorm quantile residuals sd shapiro.test diff --git a/R/summary_graph.R b/R/summary_graph.R index 5e9d1bc..181a9ca 100644 --- a/R/summary_graph.R +++ b/R/summary_graph.R @@ -1,12 +1,12 @@ -#' Summary Graph +#' Visualise a graphical summary of variables from a data frame #' -#' Produce a graphical summary of variables from a data frame. Variables are plotted -#' as box plots, grouped and, if enough variables are provided, coloured and facetted. +#' Variables are plotted in different ways according to the number of explanatory +#' variables provided as input. #' #' @param data A data frame containing the variables to be plotted. #' @param response The response variable to plot. -#' @param exp_var The explanatory (or grouping) variable to plot. -#' @param resp_units A string providing units to display on the response variable axis. +#' @param exp_var The explanatory (or grouping) variable(s) to plot. Up to three can be provided. +#' @param resp_units A string providing units to display on the response variable (y) axis. Will use the empty string by default so axes will have no units by default. #' #' @importFrom ggplot2 ggplot aes geom_boxplot stat_summary facet_wrap geom_point labs theme_bw #' @importFrom rlang ensym ensyms as_string @@ -14,13 +14,24 @@ #' @return A ggplot2 plot object #' @export #' +#' @details +#' With a single explanatory variable, a boxplot grouped by `exp_var` is produced. +#' With two explanatory variables, a dot-plot with lines connecting the mean of each +#' group is produced, with the first element of `exp_var` used as the x axis variable, +#' and the second is used to colour the points. Three explanatory variables produces +#' the same as two, but with the third used to facet the plot. +#' #' @examples #' #' summary_graph(iris, "Petal.Length", "Species", "mm") -#' summary_graph(iris, Petal.Length, "Species", "mm") +#' +#' # Multiple +#' summary_graph(npk, "yield", c("N", "P"), "lb/plot") +#' +# # Three way interaction #' summary_graph(npk, "yield", c("N", "P", "K"), "lb/plot") #' -summary_graph <- function(data, response, exp_var, resp_units) { +summary_graph <- function(data, response, exp_var, resp_units = "") { # TODO: NSE @@ -33,10 +44,10 @@ summary_graph <- function(data, response, exp_var, resp_units) { stop(rlang::as_string(response), " does not appear to be a column of data. Please check input.", call. = FALSE) } if(!is.numeric(data[[rlang::as_string(response)]])) { - warning(rlang::as_string(response), " is not a numeric variable.") + stop(rlang::as_string(response), " is not a numeric variable.") } if(!is.character(resp_units)) { - stop("resp_units must be provided as a string.") + stop("resp_units must be provided as a string with quotes.") } @@ -60,12 +71,17 @@ summary_graph <- function(data, response, exp_var, resp_units) { ggplot2::facet_wrap(~ .data[[exp_var[3]]]) } else { - stop("Additional explanatory variables are not currently handled.") + stop("Additional explanatory variables are not currently supported.") } + if(resp_units!="") { + gg <- gg + ggplot2::labs(y = paste({{ response }}, " (", resp_units, ")", sep = "")) + + } gg <- gg + ggplot2::geom_point(alpha = 0.3) + - ggplot2::labs(y = paste({{ response }}, " (", resp_units, ")", sep = "")) + ggplot2::theme_bw() return(gg) } + + diff --git a/R/utility_functions.R b/R/utility_functions.R index 7059a22..ec371b2 100644 --- a/R/utility_functions.R +++ b/R/utility_functions.R @@ -21,15 +21,15 @@ quiet <- function(x) { # this function is executed once the package is loaded ###################################################### -#' @importFrom utils available.packages packageVersion +#' @importFrom utils available.packages packageVersion compareVersion #' @importFrom rlang is_interactive is_installed .onAttach <- function(library, pkg) { - installed_version <- utils::packageVersion('biometryassist') + local_version <- utils::packageVersion('biometryassist') if(rlang::is_interactive() && !isFALSE(rlang::peek_option("biometryassist.check"))) { output <- paste(paste0(" ", paste0(rep("~", times = 69), collapse = "")), - paste(" | ", pkg, " version ", installed_version, " |",sep=""), + paste(" | ", pkg, " version ", local_version, " |",sep=""), " | Authors: Sharon Nielsen, Sam Rogers, Annie Conway |", " | Developed at the University of Adelaide with funding provided |", " | by the Australian Grains Research and Development Corporation. |", @@ -47,7 +47,7 @@ quiet <- function(x) { } # check which version is more recent - current_version <- tryCatch( + cran_version <- tryCatch( { packages <- utils::available.packages() ver <- packages["biometryassist","Version"] @@ -57,11 +57,22 @@ quiet <- function(x) { } ) - if(!is.na(current_version) && current_version > installed_version) { # current version on CRAN newer than installed - warning(" biometryassist version ", current_version, " is now available.\n", + if(compare_version(cran_version, as.character(local_version)) == 1) { # current version on CRAN newer than installed + warning(" biometryassist version ", cran_version, " is now available.\n", " Please update biometryassist by running\n", " install.packages('biometryassist')", call. = FALSE) } } invisible() } + +#' Function to compare package version for mocking +#' +#' @param a One package version +#' @param b Another package version +#' +#' @return +#' @keywords internal +compare_version <- function(a, b) { + return(utils::compareVersion(as.character(a), as.character(b))) +} diff --git a/R/variogram.r b/R/variogram.r index bd2ee74..0015f4a 100644 --- a/R/variogram.r +++ b/R/variogram.r @@ -1,4 +1,4 @@ -#' Variogram plots for spatial models. +#' Display variogram plots for spatial models #' #' Produces variogram plots for checking spatial trends. #' diff --git a/_pkgdown.yml b/_pkgdown.yml index 9de9761..bc7ee95 100644 --- a/_pkgdown.yml +++ b/_pkgdown.yml @@ -9,18 +9,18 @@ template: reference: - title: Design - desc: Functions to help with the design of experiments + desc: Functions to help with the design of experiments. - contents: - starts_with("des") - title: Analysis - desc: Functions to help with the analysis of experiments + desc: Functions to help with the analysis of experiments. - contents: - resplot - multiple_comparisons - variogram - logl_test - title: Utilities - desc: Other helper functions + desc: Other helper functions. - contents: - autoplot - heat_map diff --git a/cran-comments.md b/cran-comments.md index 6bb42f1..ecdd836 100644 --- a/cran-comments.md +++ b/cran-comments.md @@ -1,6 +1,6 @@ ## Submission -Resubmission. Extra files removed, apologies. This version add some new features and fixes some minor bugs. +Resubmission with incremented version number. One of the functions I was intending to submit with previous (1.2.0) update was excluded via .Rbuildignore - now included. ## Test environments * Local Windows 10 install, R 4.4.0 @@ -18,4 +18,4 @@ There was 1 NOTE: * checking package dependencies ... NOTE Packages which this enhances but not available for checking: - 'asreml', 'ARTool', 'sommer' + 'asreml' diff --git a/man/autoplot.Rd b/man/autoplot.Rd index bce8933..6cbfe5a 100644 --- a/man/autoplot.Rd +++ b/man/autoplot.Rd @@ -4,7 +4,7 @@ \alias{autoplot} \alias{autoplot.mct} \alias{autoplot.design} -\title{Automatic plots for objects generated in biometryassist} +\title{Generate automatic plots for objects generated in biometryassist} \usage{ autoplot(object, ...) @@ -65,7 +65,7 @@ autoplot(object, ...) A \code{ggplot2} object. } \description{ -Automatic plots for objects generated in biometryassist +Generate automatic plots for objects generated in biometryassist } \examples{ dat.aov <- aov(Petal.Width ~ Species, data = iris) diff --git a/man/des_info.Rd b/man/des_info.Rd index 9acb53b..573325a 100644 --- a/man/des_info.Rd +++ b/man/des_info.Rd @@ -2,7 +2,7 @@ % Please edit documentation in R/des_info.R \name{des_info} \alias{des_info} -\title{Produces graph of design layout, skeletal ANOVA table and data frame with complete design} +\title{Produce a graph of design layout, skeletal ANOVA table and data frame with complete design} \usage{ des_info( design.obj, @@ -48,7 +48,7 @@ des_info( \item{size}{Increase or decrease the text size within the plot for treatment labels. Numeric with default value of 4.} -\item{margin}{Logical (default FALSE). Expand the plot to the edges of the plotting area i.e. remove white space between plot and axes.} +\item{margin}{Logical (default FALSE). Setting to \code{TRUE} will add a margin (white space) between plot and axes.} \item{save}{One of \code{FALSE} (default)/\code{"none"}, \code{TRUE}/\code{"both"}, \code{"plot"} or \code{"workbook"}. Specifies which output to save.} @@ -66,7 +66,7 @@ des_info( A list containing a data frame with the complete design, a ggplot object with plot layout, the seed (if \code{return.seed = TRUE}), and the \code{satab} object, allowing repeat output of the \code{satab} table via \code{cat(output$satab)}. } \description{ -Produces graph of design layout, skeletal ANOVA table and data frame with complete design +Produce a graph of design layout, skeletal ANOVA table and data frame with complete design } \details{ If \code{save = TRUE} (or \code{"both"}), both the plot and the workbook will be saved to the current working directory, with filename given by \code{savename}. If one of either \code{"plot"} or \code{"workbook"} is specified, only that output is saved. If \code{save = FALSE} (the default, or equivalently \code{"none"}), nothing will be output. diff --git a/man/design.Rd b/man/design.Rd index ea5cfac..0187194 100644 --- a/man/design.Rd +++ b/man/design.Rd @@ -2,7 +2,7 @@ % Please edit documentation in R/design.R \name{design} \alias{design} -\title{Produces an experimental design with graph of design layout and skeletal ANOVA table} +\title{Create a complete experimental design with graph of design layout and skeletal ANOVA table} \usage{ design( type, @@ -29,11 +29,11 @@ design( ) } \arguments{ -\item{type}{The type of design. Supported design types are \code{crd}, \code{rcbd}, \code{lsd}, \verb{crossed:} where \verb{} is one of the previous types and \code{split}. See Details for more information.} +\item{type}{The type of design. Supported design types are \code{crd}, \code{rcbd}, \code{lsd}, \verb{crossed:} where \verb{} is one of the previous types, and \code{split}. See Details for more information.} \item{treatments}{A vector containing the treatment names or labels.} -\item{reps}{The number of replicates. Not required for Latin Squared Designs.} +\item{reps}{The number of replicates. Ignored for Latin Square Designs.} \item{nrows}{The number of rows in the design.} @@ -45,7 +45,7 @@ design( \item{byrow}{For split-plot only. Logical (default \code{TRUE}). Provides a way to arrange plots within whole-plots when there are multiple possible arrangements.} -\item{sub_treatments}{A vector of treatments for subplots in a split plot design.} +\item{sub_treatments}{A vector of treatments for sub-plots in a split plot design.} \item{fac.names}{Allows renaming of the \code{A} level of factorial designs (i.e. those using \code{\link[agricolae:design.ab]{agricolae::design.ab()}}) by passing (optionally named) vectors of new labels to be applied to the factors within a list. See examples and details for more information.} @@ -61,7 +61,7 @@ design( \item{save}{One of \code{FALSE} (default)/\code{"none"}, \code{TRUE}/\code{"both"}, \code{"plot"} or \code{"workbook"}. Specifies which output to save.} -\item{savename}{A filename for the design to be saved to. Default is the type of the design combined with "_design".} +\item{savename}{A file name for the design to be saved to. Default is the type of the design combined with "_design".} \item{plottype}{The type of file to save the plot as. Usually one of \code{"pdf"}, \code{"png"}, or \code{"jpg"}. See \code{\link[ggplot2:ggsave]{ggplot2::ggsave()}} for all possible options.} @@ -75,7 +75,7 @@ design( A list containing a data frame with the complete design (\verb{$design}), a ggplot object with plot layout (\verb{$plot.des}), the seed (\verb{$seed}, if \code{return.seed = TRUE}), and the \code{satab} object (\verb{$satab}), allowing repeat output of the \code{satab} table via \code{cat(output$satab)}. } \description{ -Produces an experimental design with graph of design layout and skeletal ANOVA table +Create a complete experimental design with graph of design layout and skeletal ANOVA table } \details{ The designs currently supported by \code{type} are Completely Randomised designs (\code{crd}), Randomised Complete Block designs (\code{rcbd}), Latin Square Designs (\code{lsd}), Factorial with crossed structure (use \verb{crossed:} where \verb{} is one of the previous types e.g. \code{crossed:crd}) and Split Plot designs (\code{split}). Nested factorial designs are supported through manual setup, see Examples. @@ -84,7 +84,7 @@ If \code{save = TRUE} (or \code{"both"}), both the plot and the workbook will be \code{fac.names} can be supplied to provide more intuitive names for factors and their levels in factorial and split plot designs. They can be specified in a list format, for example \code{fac.names = list(A_names = c("a", "b", "c"), B_names = c("x", "y", "z"))}. This will result a design output with a column named \code{A_names} with levels \verb{a, b, c} and another named \code{B_names} with levels \verb{x, y, z}. Labels can also be supplied as a character vector (e.g. \code{c("A", "B")}) which will result in only the treatment column names being renamed. Only the first two elements of the list will be used, except in the case of a 3-way factorial design. -\code{...} allows extra arguments to be passed to ggsave for output of the plot. The details of possible arguments can be found in \code{\link[ggplot2:ggsave]{ggplot2::ggsave()}}. +\code{...} allows extra arguments to be passed to \code{ggsave()} for output of the plot. The details of possible arguments can be found in \code{\link[ggplot2:ggsave]{ggplot2::ggsave()}}. } \examples{ # Completely Randomised Design diff --git a/man/heat_map.Rd b/man/heat_map.Rd index 4887906..1fa75f7 100644 --- a/man/heat_map.Rd +++ b/man/heat_map.Rd @@ -2,7 +2,7 @@ % Please edit documentation in R/heatmap.R \name{heat_map} \alias{heat_map} -\title{Heatmap} +\title{Produce a heatmap of variables in a grid layout.} \usage{ heat_map( data, @@ -12,13 +12,14 @@ heat_map( grouping = NULL, raster = TRUE, smooth = FALSE, - palette = "default" + palette = "default", + ... ) } \arguments{ -\item{data}{A data frame containing the data to be plotted} +\item{data}{A data frame containing the data to be plotted.} -\item{value}{A column of \code{data}, containing the values that vary over the space which produces the colours} +\item{value}{A column of \code{data}, containing the values that vary over the space which produces the colours.} \item{x_axis}{The column of \code{data} to use as the x axis data.} @@ -28,15 +29,17 @@ heat_map( \item{raster}{Logical (default: \code{TRUE}). If \code{TRUE} uses \code{\link[ggplot2:geom_tile]{ggplot2::geom_raster()}} for speed. Will not work if the grid is irregular.} -\item{smooth}{Logical (default: \code{TRUE}). If \code{raster} is \code{TRUE}, interpolation can be applied across the grid to obtain a smoothed grid. Ignored if \code{raster} is \code{FALSE}.} +\item{smooth}{Logical (default: \code{FALSE}). If \code{raster} is \code{TRUE}, interpolation can be applied across the grid to obtain a smoothed grid. Ignored if \code{raster} is \code{FALSE}.} -\item{palette}{Colour palatte to use. By default it will use the \code{viridis} (colour-blind friendly) palette. Other palettes available can be seen with \code{\link[grDevices:palettes]{grDevices::hcl.pals()}}.} +\item{palette}{Colour palette to use. By default it will use the \code{viridis} (colour-blind friendly) palette. Other palettes available can be seen with \code{\link[grDevices:palettes]{grDevices::hcl.pals()}}.} + +\item{...}{Other arguments passed to \code{\link[=facet_wrap]{facet_wrap()}}} } \value{ A \code{ggplot2} object. } \description{ -Function to plot heatmaps of variables in a grid layout. +This function plots a heatmap of variables in a grid layout, optionally grouping them. } \examples{ @@ -46,5 +49,15 @@ dat$value <- rnorm(30) dat$groups <- sample(rep(LETTERS[1:6], times = 5)) heat_map(dat, value, x, y) + +# Column names can be quoted, but don't need to be. heat_map(dat, "value", "x", "y", "groups") + +# Different palettes are available +heat_map(dat, value, x, y, palette = "Spectral") + +# Arguments in ... are passed through to facet_wrap +heat_map(dat, value, x, y, groups, labeller = ggplot2:::label_both) +heat_map(dat, value, x, y, groups, scales = "free_y") +heat_map(dat, value, x, y, groups, nrow = 1) } diff --git a/man/install_asreml.Rd b/man/install_asreml.Rd index da0d2d0..ae49263 100644 --- a/man/install_asreml.Rd +++ b/man/install_asreml.Rd @@ -3,7 +3,7 @@ \name{install_asreml} \alias{install_asreml} \alias{update_asreml} -\title{Install or Update the ASReml-R package} +\title{Install or update the ASReml-R package} \usage{ install_asreml( library = .libPaths()[1], diff --git a/man/logl_test.Rd b/man/logl_test.Rd index b533ce0..e7bda99 100644 --- a/man/logl_test.Rd +++ b/man/logl_test.Rd @@ -2,7 +2,7 @@ % Please edit documentation in R/logltest.R \name{logl_test} \alias{logl_test} -\title{Log-likelihood test for comparing terms in ASReml-R models} +\title{Conduct a log-likelihood test for comparing terms in ASReml-R models} \usage{ logl_test( model.obj, @@ -30,7 +30,7 @@ logl_test( A dataframe containing the results of the test. } \description{ -Log-likelihood test for comparing terms in ASReml-R models +Conduct a log-likelihood test for comparing terms in ASReml-R models } \details{ Typically p-values cannot be 0, and are usually just below some threshold of accuracy in calculation of probability. diff --git a/man/multiple_comparisons.Rd b/man/multiple_comparisons.Rd index 09dd5ff..f868781 100644 --- a/man/multiple_comparisons.Rd +++ b/man/multiple_comparisons.Rd @@ -2,7 +2,7 @@ % Please edit documentation in R/mct.R \name{multiple_comparisons} \alias{multiple_comparisons} -\title{Multiple Comparison Tests} +\title{Perform Multiple Comparison Tests on a statistical model} \usage{ multiple_comparisons( model.obj, diff --git a/man/print.mct.Rd b/man/print.mct.Rd index 2bb8471..8b2813c 100644 --- a/man/print.mct.Rd +++ b/man/print.mct.Rd @@ -2,7 +2,7 @@ % Please edit documentation in R/mct.R \name{print.mct} \alias{print.mct} -\title{Print method for multiple_comparisons} +\title{Print output of multiple_comparisons} \usage{ \method{print}{mct}(x, ...) } @@ -15,7 +15,7 @@ The original object invisibly. } \description{ -Print method for multiple_comparisons +Print output of multiple_comparisons } \examples{ dat.aov <- aov(Petal.Width ~ Species, data = iris) diff --git a/man/resplot.Rd b/man/resplot.Rd index 80b1a71..ad58aac 100644 --- a/man/resplot.Rd +++ b/man/resplot.Rd @@ -2,7 +2,7 @@ % Please edit documentation in R/resplot.R \name{resplot} \alias{resplot} -\title{Residual plots of linear models.} +\title{Produce residual plots of linear models} \usage{ resplot( model.obj, @@ -30,7 +30,7 @@ resplot( \item{mod.obj}{Deprecated to be consistent with other functions. Please use \code{model.obj} instead.} } \value{ -A list containing ggplot2 objects which are diagnostic plots. +A ggplot2 object containing the diagnostic plots. } \description{ Produces plots of residuals for assumption checking of linear (mixed) models. diff --git a/man/summary_graph.Rd b/man/summary_graph.Rd index 658ac5c..2202a1b 100644 --- a/man/summary_graph.Rd +++ b/man/summary_graph.Rd @@ -2,30 +2,40 @@ % Please edit documentation in R/summary_graph.R \name{summary_graph} \alias{summary_graph} -\title{Summary Graph} +\title{Visualise a graphical summary of variables from a data frame} \usage{ -summary_graph(data, response, exp_var, resp_units) +summary_graph(data, response, exp_var, resp_units = "") } \arguments{ \item{data}{A data frame containing the variables to be plotted.} \item{response}{The response variable to plot.} -\item{exp_var}{The explanatory (or grouping) variable to plot.} +\item{exp_var}{The explanatory (or grouping) variable(s) to plot. Up to three can be provided.} -\item{resp_units}{A string providing units to display on the response variable axis.} +\item{resp_units}{A string providing units to display on the response variable (y) axis. Will use the empty string by default so axes will have no units by default.} } \value{ A ggplot2 plot object } \description{ -Produce a graphical summary of variables from a data frame. Variables are plotted -as box plots, grouped and, if enough variables are provided, coloured and facetted. +Variables are plotted in different ways according to the number of explanatory +variables provided as input. +} +\details{ +With a single explanatory variable, a boxplot grouped by \code{exp_var} is produced. +With two explanatory variables, a dot-plot with lines connecting the mean of each +group is produced, with the first element of \code{exp_var} used as the x axis variable, +and the second is used to colour the points. Three explanatory variables produces +the same as two, but with the third used to facet the plot. } \examples{ summary_graph(iris, "Petal.Length", "Species", "mm") -summary_graph(iris, Petal.Length, "Species", "mm") + +# Multiple +summary_graph(npk, "yield", c("N", "P"), "lb/plot") + summary_graph(npk, "yield", c("N", "P", "K"), "lb/plot") } diff --git a/man/variogram.Rd b/man/variogram.Rd index 86920c8..c5332a3 100644 --- a/man/variogram.Rd +++ b/man/variogram.Rd @@ -2,7 +2,7 @@ % Please edit documentation in R/variogram.r \name{variogram} \alias{variogram} -\title{Variogram plots for spatial models.} +\title{Display variogram plots for spatial models} \usage{ variogram( model.obj, diff --git a/tests/testthat/_snaps/design/crd-paired-palatte.svg b/tests/testthat/_snaps/design/crd-paired-palette.svg similarity index 99% rename from tests/testthat/_snaps/design/crd-paired-palatte.svg rename to tests/testthat/_snaps/design/crd-paired-palette.svg index e75aa54..53c316a 100644 --- a/tests/testthat/_snaps/design/crd-paired-palatte.svg +++ b/tests/testthat/_snaps/design/crd-paired-palette.svg @@ -217,6 +217,6 @@ I J K -CRD Paired palatte +CRD Paired palette diff --git a/tests/testthat/_snaps/design/crd-rdbu-palatte.svg b/tests/testthat/_snaps/design/crd-rdbu-palette.svg similarity index 99% rename from tests/testthat/_snaps/design/crd-rdbu-palatte.svg rename to tests/testthat/_snaps/design/crd-rdbu-palette.svg index 6dc3b81..79f5cef 100644 --- a/tests/testthat/_snaps/design/crd-rdbu-palatte.svg +++ b/tests/testthat/_snaps/design/crd-rdbu-palette.svg @@ -217,6 +217,6 @@ I J K -CRD RdBu palatte +CRD RdBu palette diff --git a/tests/testthat/_snaps/design/crd-set3-palatte.svg b/tests/testthat/_snaps/design/crd-set3-palette.svg similarity index 99% rename from tests/testthat/_snaps/design/crd-set3-palatte.svg rename to tests/testthat/_snaps/design/crd-set3-palette.svg index 165ff46..6ce9820 100644 --- a/tests/testthat/_snaps/design/crd-set3-palatte.svg +++ b/tests/testthat/_snaps/design/crd-set3-palette.svg @@ -217,6 +217,6 @@ I J K -CRD Set3 palatte +CRD Set3 palette diff --git a/tests/testthat/_snaps/design/rcbd-paired-palatte.svg b/tests/testthat/_snaps/design/rcbd-paired-palette.svg similarity index 99% rename from tests/testthat/_snaps/design/rcbd-paired-palatte.svg rename to tests/testthat/_snaps/design/rcbd-paired-palette.svg index 216cb1f..e9d1945 100644 --- a/tests/testthat/_snaps/design/rcbd-paired-palatte.svg +++ b/tests/testthat/_snaps/design/rcbd-paired-palette.svg @@ -225,6 +225,6 @@ I J K -RCBD Paired palatte +RCBD Paired palette diff --git a/tests/testthat/_snaps/design/rcbd-rdbu-palatte.svg b/tests/testthat/_snaps/design/rcbd-rdbu-palette.svg similarity index 99% rename from tests/testthat/_snaps/design/rcbd-rdbu-palatte.svg rename to tests/testthat/_snaps/design/rcbd-rdbu-palette.svg index 23d11d3..5835241 100644 --- a/tests/testthat/_snaps/design/rcbd-rdbu-palatte.svg +++ b/tests/testthat/_snaps/design/rcbd-rdbu-palette.svg @@ -225,6 +225,6 @@ I J K -RCBD RdBu palatte +RCBD RdBu palette diff --git a/tests/testthat/_snaps/design/rcbd-set3-palatte.svg b/tests/testthat/_snaps/design/rcbd-set3-palette.svg similarity index 99% rename from tests/testthat/_snaps/design/rcbd-set3-palatte.svg rename to tests/testthat/_snaps/design/rcbd-set3-palette.svg index ea03ec0..9384a90 100644 --- a/tests/testthat/_snaps/design/rcbd-set3-palatte.svg +++ b/tests/testthat/_snaps/design/rcbd-set3-palette.svg @@ -225,6 +225,6 @@ I J K -RCBD Set3 palatte +RCBD Set3 palette diff --git a/tests/testthat/_snaps/heatmap/heatmap-of-generated-data.svg b/tests/testthat/_snaps/heatmap/heatmap-of-generated-data.svg new file mode 100644 index 0000000..9f73322 --- /dev/null +++ b/tests/testthat/_snaps/heatmap/heatmap-of-generated-data.svg @@ -0,0 +1,86 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +2 +4 +6 + + + + + + + + +1 +2 +3 +4 +5 +x +y + +value + + + + + + + + + +-1 +0 +1 +2 +Heatmap of generated data + + diff --git a/tests/testthat/_snaps/heatmap/heatmap-of-grouped-data.svg b/tests/testthat/_snaps/heatmap/heatmap-of-grouped-data.svg new file mode 100644 index 0000000..008ca7e --- /dev/null +++ b/tests/testthat/_snaps/heatmap/heatmap-of-grouped-data.svg @@ -0,0 +1,323 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +D + + + + + + + + + + +E + + + + + + + + + + +F + + + + + + + + + + +A + + + + + + + + + + +B + + + + + + + + + + +C + + + + + + + +1 +2 +3 +4 +5 + + + + + +1 +2 +3 +4 +5 + + + + + +1 +2 +3 +4 +5 +2 +4 +6 + + + +2 +4 +6 + + + +x +y + +value + + + + + + + + + +-1 +0 +1 +2 +Heatmap of grouped data + + diff --git a/tests/testthat/_snaps/heatmap/heatmap-of-interpolated-data.svg b/tests/testthat/_snaps/heatmap/heatmap-of-interpolated-data.svg new file mode 100644 index 0000000..2078130 --- /dev/null +++ b/tests/testthat/_snaps/heatmap/heatmap-of-interpolated-data.svg @@ -0,0 +1,86 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +2 +4 +6 + + + + + + + + +1 +2 +3 +4 +5 +x +y + +value + + + + + + + + + +-1 +0 +1 +2 +Heatmap of interpolated data + + diff --git a/tests/testthat/_snaps/heatmap/heatmap-of-interpolated-grouped-data.svg b/tests/testthat/_snaps/heatmap/heatmap-of-interpolated-grouped-data.svg new file mode 100644 index 0000000..da877ab --- /dev/null +++ b/tests/testthat/_snaps/heatmap/heatmap-of-interpolated-grouped-data.svg @@ -0,0 +1,323 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +D + + + + + + + + + + +E + + + + + + + + + + +F + + + + + + + + + + +A + + + + + + + + + + +B + + + + + + + + + + +C + + + + + + + +1 +2 +3 +4 +5 + + + + + +1 +2 +3 +4 +5 + + + + + +1 +2 +3 +4 +5 +2 +4 +6 + + + +2 +4 +6 + + + +x +y + +value + + + + + + + + + +-1 +0 +1 +2 +Heatmap of interpolated grouped data + + diff --git a/tests/testthat/_snaps/heatmap/heatmap-using-geom-tile.svg b/tests/testthat/_snaps/heatmap/heatmap-using-geom-tile.svg new file mode 100644 index 0000000..c1599e3 --- /dev/null +++ b/tests/testthat/_snaps/heatmap/heatmap-using-geom-tile.svg @@ -0,0 +1,115 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +2 +4 +6 + + + + + + + + +1 +2 +3 +4 +5 +x +y + +value + + + + + + + + + +-1 +0 +1 +2 +Heatmap using geom_tile + + diff --git a/tests/testthat/_snaps/heatmap/heatmap-with-facet-labels.svg b/tests/testthat/_snaps/heatmap/heatmap-with-facet-labels.svg new file mode 100644 index 0000000..5a70409 --- /dev/null +++ b/tests/testthat/_snaps/heatmap/heatmap-with-facet-labels.svg @@ -0,0 +1,323 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +groups: D + + + + + + + + + + +groups: E + + + + + + + + + + +groups: F + + + + + + + + + + +groups: A + + + + + + + + + + +groups: B + + + + + + + + + + +groups: C + + + + + + + +1 +2 +3 +4 +5 + + + + + +1 +2 +3 +4 +5 + + + + + +1 +2 +3 +4 +5 +2 +4 +6 + + + +2 +4 +6 + + + +x +y + +value + + + + + + + + + +-1 +0 +1 +2 +Heatmap with facet labels + + diff --git a/tests/testthat/_snaps/heatmap/heatmap-with-free-y.svg b/tests/testthat/_snaps/heatmap/heatmap-with-free-y.svg new file mode 100644 index 0000000..aaef09a --- /dev/null +++ b/tests/testthat/_snaps/heatmap/heatmap-with-free-y.svg @@ -0,0 +1,387 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +D + + + + + + + + + + +E + + + + + + + + + + +F + + + + + + + + + + +A + + + + + + + + + + +B + + + + + + + + + + +C + + + + + + + +1 +2 +3 +4 +5 + + + + + +1 +2 +3 +4 +5 + + + + + +1 +2 +3 +4 +5 +1 +2 +3 +4 +5 + + + + + +2.5 +3.5 +4.5 +5.5 +6.5 + + + + + +2 +4 +6 + + + +1.5 +2.0 +2.5 +3.0 +3.5 +4.0 +4.5 + + + + + + + +2 +4 +6 + + + +2 +3 +4 +5 +6 + + + + + +x +y + +value + + + + + + + + + +-1 +0 +1 +2 +Heatmap with free_y + + diff --git a/tests/testthat/_snaps/heatmap/heatmap-with-one-row.svg b/tests/testthat/_snaps/heatmap/heatmap-with-one-row.svg new file mode 100644 index 0000000..286e594 --- /dev/null +++ b/tests/testthat/_snaps/heatmap/heatmap-with-one-row.svg @@ -0,0 +1,347 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +A + + + + + + + + + + +B + + + + + + + + + + +C + + + + + + + + + + +D + + + + + + + + + + +E + + + + + + + + + + +F + + + + + + + +1 +2 +3 +4 +5 + + + + + +1 +2 +3 +4 +5 + + + + + +1 +2 +3 +4 +5 + + + + + +1 +2 +3 +4 +5 + + + + + +1 +2 +3 +4 +5 + + + + + +1 +2 +3 +4 +5 +2 +4 +6 + + + +x +y + +value + + + + + + + + + +-1 +0 +1 +2 +Heatmap with one row + + diff --git a/tests/testthat/_snaps/heatmap/heatmap-with-red-green-palette.svg b/tests/testthat/_snaps/heatmap/heatmap-with-red-green-palette.svg new file mode 100644 index 0000000..70abda3 --- /dev/null +++ b/tests/testthat/_snaps/heatmap/heatmap-with-red-green-palette.svg @@ -0,0 +1,86 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +2 +4 +6 + + + + + + + + +1 +2 +3 +4 +5 +x +y + +value + + + + + + + + + +-1 +0 +1 +2 +Heatmap with red-green palette + + diff --git a/tests/testthat/_snaps/heatmap/heatmap-with-spectral-palette.svg b/tests/testthat/_snaps/heatmap/heatmap-with-spectral-palette.svg new file mode 100644 index 0000000..bc4e8fd --- /dev/null +++ b/tests/testthat/_snaps/heatmap/heatmap-with-spectral-palette.svg @@ -0,0 +1,86 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +2 +4 +6 + + + + + + + + +1 +2 +3 +4 +5 +x +y + +value + + + + + + + + + +-1 +0 +1 +2 +Heatmap with spectral palette + + diff --git a/tests/testthat/_snaps/resplot/resplot-for-asreml-single.svg b/tests/testthat/_snaps/resplot/resplot-for-asreml-single.svg index 350220a..9681d2b 100644 --- a/tests/testthat/_snaps/resplot/resplot-for-asreml-single.svg +++ b/tests/testthat/_snaps/resplot/resplot-for-asreml-single.svg @@ -31,8 +31,10 @@ -asreml::asreml(fixed = Petal.Length ~ Petal.Width, -data = iris, trace = FALSE) +asreml(fixed = yield ~ Nitrogen + Variety + Nitrogen:Variety, +random = ~Blocks + Blocks:Wplots, residual = ~ar1(Row):ar1(Column), +R.param = model.asr$R.param, +data = dat) @@ -54,60 +56,64 @@ - - + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + -0 -10 -20 -30 -40 - - - - - - - - --2 -0 -2 -Standardised Residual +0 +3 +6 +9 + + + + + + + + + +-2 +-1 +0 +1 +2 +Standardised Residual Frequency A @@ -128,208 +134,124 @@ - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + --3 --2 --1 -0 -1 -2 -3 - - - - - - - - - +-2 +-1 +0 +1 +2 + + + + + + + - - --2 --1 + + +-2 +-1 0 -1 -2 +1 +2 Theoretical Standardised Residual B @@ -360,207 +282,117 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + --3 --2 --1 -0 -1 -2 -3 - - - - - - - - - - - - -2 -3 -4 -5 -6 +-2 +-1 +0 +1 +2 + + + + + + + + + +75 +100 +125 +150 Fitted Value Standardised Residual C diff --git a/tests/testthat/_snaps/utility_functions.md b/tests/testthat/_snaps/utility_functions.md index 9c0773a..c5cfde8 100644 --- a/tests/testthat/_snaps/utility_functions.md +++ b/tests/testthat/_snaps/utility_functions.md @@ -4,7 +4,7 @@ biometryassist:::.onAttach(pkg = "biometryassist") Message ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - | biometryassist version 1.2.0 | + | biometryassist version 1.2.1 | | Authors: Sharon Nielsen, Sam Rogers, Annie Conway | | Developed at the University of Adelaide with funding provided | | by the Australian Grains Research and Development Corporation. | diff --git a/tests/testthat/test-design.R b/tests/testthat/test-design.R index cc85cca..d79cf07 100644 --- a/tests/testthat/test-design.R +++ b/tests/testthat/test-design.R @@ -685,7 +685,7 @@ test_that("Various colour blind spellings and options", { }) -test_that("Alternative palattes work", { +test_that("Alternative palettes work", { # CRD d1 <- design("crd", treatments = LETTERS[1:11], reps = 4, nrows = 11, ncols = 4, seed = 42, quiet = TRUE, plot = FALSE) @@ -696,12 +696,12 @@ test_that("Alternative palattes work", { seed = 42, quiet = TRUE, plot = FALSE) - vdiffr::expect_doppelganger(title = "CRD RdBu palatte", autoplot(d1, palette = "RdBu")) - vdiffr::expect_doppelganger(title = "CRD Set3 palatte", autoplot(d1, palette = "Set3")) - vdiffr::expect_doppelganger(title = "CRD Paired palatte", autoplot(d1, palette = "Paired")) - vdiffr::expect_doppelganger(title = "RCBD RdBu palatte", autoplot(d2, palette = "RdBu")) - vdiffr::expect_doppelganger(title = "RCBD Set3 palatte", autoplot(d2, palette = "Set3")) - vdiffr::expect_doppelganger(title = "RCBD Paired palatte", autoplot(d2, palette = "Paired")) + vdiffr::expect_doppelganger(title = "CRD RdBu palette", autoplot(d1, palette = "RdBu")) + vdiffr::expect_doppelganger(title = "CRD Set3 palette", autoplot(d1, palette = "Set3")) + vdiffr::expect_doppelganger(title = "CRD Paired palette", autoplot(d1, palette = "Paired")) + vdiffr::expect_doppelganger(title = "RCBD RdBu palette", autoplot(d2, palette = "RdBu")) + vdiffr::expect_doppelganger(title = "RCBD Set3 palette", autoplot(d2, palette = "Set3")) + vdiffr::expect_doppelganger(title = "RCBD Paired palette", autoplot(d2, palette = "Paired")) }) test_that("Invalid palette option produces error", { @@ -753,6 +753,16 @@ test_that("Adding buffers to plots works for RCBD", { autoplot(d2, buffer = "double column")) }) +test_that("Invalid buffer options produce an error", { + # RCBD + d2 <- design("rcbd", treatments = LETTERS[1:11], reps = 4, + nrows = 11, ncols = 4, brows = 11, bcols = 1, + seed = 42, quiet = TRUE, plot = FALSE) + + expect_error(autoplot(d2, buffer = "block"), "Block buffers are not yet supported\\.") + expect_error(autoplot(d2, buffer = "abc"), "Invalid buffer option: abc") +}) + # test_that("Buffers are produced when abreviations are given", { # # CRD # d1 <- design("crd", treatments = LETTERS[1:11], reps = 4, diff --git a/tests/testthat/test-heatmap.R b/tests/testthat/test-heatmap.R new file mode 100644 index 0000000..9975989 --- /dev/null +++ b/tests/testthat/test-heatmap.R @@ -0,0 +1,66 @@ +set.seed(42) +dat <- expand.grid(x = 1:5, y = 1:6) +dat$value <- rnorm(30) +dat$groups <- sample(rep(LETTERS[1:6], times = 5)) + +test_that("Invalid data argument produces an error", { + expect_error(heat_map("abc", value, x, y), + "abc is not a data frame\\.") +}) + +test_that("heat_map produces a ggplot object", { + hm <- heat_map(dat, value, x, y) + expect_s3_class(hm, "gg") + expect_s3_class(hm, "ggplot") +}) + +test_that("heat_map produces an image", { + vdiffr::expect_doppelganger(title = "Heatmap of generated data", + heat_map(dat, value, x, y)) +}) + + +test_that("NSE produces identical results", { + hm1 <- heat_map(dat, "value", "x", "y") + hm2 <- heat_map(dat, value, x, y) + expect_identical(hm1, hm2) +}) + +test_that("heat_map produces a grouped plot", { + vdiffr::expect_doppelganger(title = "Heatmap of grouped data", + heat_map(dat, value, x, y, groups)) +}) + +test_that("heat_map produces a grouped plot", { + vdiffr::expect_doppelganger(title = "Heatmap of grouped data", + heat_map(dat, value, x, y, groups)) +}) + +test_that("raster=FALSE uses geom_tile", { + vdiffr::expect_doppelganger(title = "Heatmap using geom_tile", + heat_map(dat, value, x, y, raster = FALSE)) +}) + +test_that("smooth argument produces an interpolated heat_map", { + vdiffr::expect_doppelganger(title = "Heatmap of interpolated data", + heat_map(dat, value, x, y, smooth = TRUE)) + vdiffr::expect_doppelganger(title = "Heatmap of interpolated grouped data", + heat_map(dat, value, x, y, groups, smooth = TRUE)) +}) + +test_that("palette argument changes the plot palette", { + vdiffr::expect_doppelganger(title = "Heatmap with spectral palette", + heat_map(dat, value, x, y, palette = "Spectral")) + vdiffr::expect_doppelganger(title = "Heatmap with red-green palette", + heat_map(dat, value, x, y, palette = "Red-Green")) +}) + +test_that("Additional arguments are passed through to facet_wrap", { + vdiffr::expect_doppelganger(title = "Heatmap with facet labels", + heat_map(dat, value, x, y, groups, labeller = ggplot2:::label_both)) + vdiffr::expect_doppelganger(title = "Heatmap with free_y", + heat_map(dat, value, x, y, groups, scales = "free_y")) + vdiffr::expect_doppelganger(title = "Heatmap with one row", + heat_map(dat, value, x, y, groups, nrow = 1)) +}) + diff --git a/tests/testthat/test-mct.R b/tests/testthat/test-mct.R index 9bb4ef8..b03d029 100644 --- a/tests/testthat/test-mct.R +++ b/tests/testthat/test-mct.R @@ -26,10 +26,8 @@ logit <- function (p, percents = range.p[2] > 1, adjust) dat.aov <- aov(Petal.Width ~ Species, data = iris) test_that("mct produces output", { - # dat.aov <- aov(Petal.Width ~ Species, data = iris) output <- multiple_comparisons(dat.aov, classify = "Species", plot = TRUE) expect_equal(output$predicted.value, c(0.25, 1.33, 2.03), tolerance = 5e-2) - # skip_if(interactive()) vdiffr::expect_doppelganger("mct output", autoplot(output)) }) @@ -73,7 +71,6 @@ test_that("transformations are handled", { expect_equal(output.power2$low, c(0.09, 1.30, 2.03), tolerance = 5e-2) expect_equal(output.power3$up, c(0.49, 1.42, 2.10), tolerance = 5e-2) - # skip_if(interactive()) vdiffr::expect_doppelganger("mct log output", autoplot(output.log)) vdiffr::expect_doppelganger("mct sqrt output", autoplot(output.sqrt)) vdiffr::expect_doppelganger("mct logit output", autoplot(output.logit)) @@ -98,7 +95,6 @@ test_that("ordering output works", { }) test_that("different interval types work", { - # dat.aov <- aov(Petal.Width ~ Species, data = iris) output1 <- multiple_comparisons(dat.aov, classify = "Species", int.type = "1se") output2 <- multiple_comparisons(dat.aov, classify = "Species", int.type = "2se") expect_equal(output1$low, c(0.22, 1.30, 2.00), tolerance = 5e-2) @@ -111,7 +107,6 @@ test_that("different interval types work", { }) test_that("save produces output", { - # dat.aov <- aov(Petal.Width ~ Species, data = iris) withr::local_file("pred_vals.csv") output <- multiple_comparisons(dat.aov, classify = "Species", save = TRUE, savename = "pred_vals") expect_snapshot_output(output) @@ -126,14 +121,11 @@ test_that("Interaction terms work", { load(test_path("data", "asreml_model.Rdata"), .GlobalEnv) skip_if_not(requireNamespace("asreml", quietly = TRUE)) quiet(library(asreml)) - # model.asr <- readRDS(test_path("data", "model_asr.rds")) - # load(test_path("data", "oats_data.Rdata"), envir = .GlobalEnv) output <- multiple_comparisons(model.asr, classify = "Nitrogen:Variety", pvals = T) expect_equal(output$predicted.value, c(70.85, 76.58, 85.86, 92.22, 99.91, 108.32, 113.1, 113.5, 116.63, 118.4, 123.75, 127.53), tolerance = 5e-2) - # skip_if(interactive()) vdiffr::expect_doppelganger("Interactions work", autoplot(output)) }) @@ -180,7 +172,6 @@ test_that("mct removes aliased treatments in aov", { test_that("mct handles aliased results in asreml with a warning", { skip_if_not(requireNamespace("asreml", quietly = TRUE)) quiet(library(asreml)) - # model.asr <- readRDS(test_path("data", "model_asr.rds")) load(test_path("data", "asreml_model.Rdata"), envir = .GlobalEnv) load(test_path("data", "oats_data.Rdata"), envir = .GlobalEnv) expect_warning( @@ -189,7 +180,7 @@ test_that("mct handles aliased results in asreml with a warning", { ), "Aliased level is: 0\\.2_cwt:Golden_rain\\." ) - # model2.asr <- readRDS(test_path("data", "model_asr2.rds")) + load(test_path("data", "oats_data2.Rdata"), envir = .GlobalEnv) expect_warning( @@ -203,11 +194,11 @@ test_that("mct handles aliased results in asreml with a warning", { }) test_that("Invalid classify argument causes an error", { - dat.aov <- aov(Petal.Width ~ Species, data = iris) - expect_error(multiple_comparisons(dat.aov, classify = "ABC"), - "ABC is not a term in the model\\. Please check model specification\\.") - expect_error(multiple_comparisons(model.asr, classify = "ABC"), - "ABC is not a term in the model\\. Please check model specification\\.") + dat.aov <- aov(Petal.Width ~ Species, data = iris) + expect_error(multiple_comparisons(dat.aov, classify = "ABC"), + "ABC is not a term in the model\\. Please check model specification\\.") + expect_error(multiple_comparisons(model.asr, classify = "ABC"), + "ABC is not a term in the model\\. Please check model specification\\.") }) test_that("Significance values that are too high give a warning", { @@ -228,35 +219,32 @@ test_that("Invalid column name causes an error", { dat.aov <- aov(rnorm(16, 10)~groups, data = dat) expect_error(multiple_comparisons(dat.aov, classify = "groups"), - "Invalid column name. Please change the name of column\\(s\\): groups") + "Invalid column name. Please change the name of column\\(s\\): groups") }) test_that("Including pred.obj object causes warning", { skip_if_not(requireNamespace("asreml", quietly = TRUE)) quiet(library(asreml)) load(test_path("data", "asreml_model.Rdata"), envir = .GlobalEnv) - # load(test_path("data", "oats_data.Rdata"), envir = .GlobalEnv) - # model.asr <- readRDS(test_path("data", "model_asr.rds")) expect_warning(multiple_comparisons(model.asr, pred.obj = pred.asr, classify = "Nitrogen"), "Argument \\`pred.obj\\` has been deprecated and will be removed in a future version\\. Predictions are now performed internally in the function\\.") }) test_that("Providing a random term in classify produces an error.", { - skip_if_not(requireNamespace("asreml", quietly = TRUE)) - expect_error(multiple_comparisons(model2.asr, classify = "Blocks"), - "All predicted values are aliased\\. Perhaps you need the `present` argument\\?") + skip_if_not(requireNamespace("asreml", quietly = TRUE)) + load(test_path("data", "oats_data2.Rdata"), envir = .GlobalEnv) + expect_error(multiple_comparisons(model2.asr, classify = "Blocks"), + "All predicted values are aliased\\. Perhaps you need the `present` argument\\?") }) test_that("lme4 model works", { skip_if_not_installed("lme4") quiet(library(lme4)) - # load(test_path("data", "oats_data.Rdata"), envir = .GlobalEnv) dat.lmer <- lmer(yield ~ Nitrogen*Variety + (1|Blocks), data = dat) output <- multiple_comparisons(dat.lmer, classify = "Nitrogen") expect_equal(output$std.error, rep(7.39, 4), tolerance = 5e-2) expect_equal(min(output$predicted.value), 79.39, tolerance = 5e-2) expect_equal(max(output$predicted.value), 123.39, tolerance = 5e-2) - # skip_on_os("linux") expect_equal(output$predicted.value, c(79.39, 98.89, 114.22, 123.39), tolerance = 5e-2) vdiffr::expect_doppelganger("lme4 output", autoplot(output)) }) diff --git a/tests/testthat/test-resplot.R b/tests/testthat/test-resplot.R index 71db88d..fac7967 100644 --- a/tests/testthat/test-resplot.R +++ b/tests/testthat/test-resplot.R @@ -25,10 +25,12 @@ test_that("Old mod.obj argument produces a warning", { }) test_that("Residual plots work for asreml", { + skip_on_cran() skip_if_not(requireNamespace("asreml", quietly = TRUE)) - dat.asr <- quiet(asreml::asreml(Petal.Length ~ Petal.Width, data = iris, trace = FALSE)) - p1_single <- resplot(dat.asr, shapiro = FALSE, call = T) + # dat.asr <- quiet(asreml::asreml(Petal.Length ~ Petal.Width, data = iris, trace = FALSE)) + load(test_path("data", "asreml_model.Rdata"), envir = .GlobalEnv) + p1_single <- resplot(model.asr, shapiro = FALSE, call = T) final.m.asr <- readRDS(test_path("data", "complex_model.rds")) p1_multi <- suppressWarnings(resplot(final.m.asr)) diff --git a/tests/testthat/test-summary_graph.R b/tests/testthat/test-summary_graph.R index 98cec86..d5118b4 100644 --- a/tests/testthat/test-summary_graph.R +++ b/tests/testthat/test-summary_graph.R @@ -1,3 +1,9 @@ +test_that("Objects produced by summary_graph are ggplot objects", { + sg <- summary_graph(iris, "Petal.Length", "Species", "mm") + expect_s3_class(sg, "gg") + expect_s3_class(sg, "ggplot") +}) + test_that("Summary graph works for one explanatory variable", { vdiffr::expect_doppelganger(title = "Summary graph of iris petal length by Species", summary_graph(iris, "Petal.Length", "Species", "mm")) @@ -15,3 +21,17 @@ test_that("Summary graph works for three explanatory variables", { summary_graph(npk, "yield", c("N", "P", "K"), "lb/plot")) }) + +test_that("Summary graph works for three explanatory variables", { + vdiffr::expect_doppelganger(title = "Summary graph of npk yield by N, P and K", + summary_graph(npk, "yield", c("N", "P", "K"), "lb/plot")) + +}) + +test_that("Errors are produced for invalid input", { + expect_error(summary_graph("abc", "def", "ghi", "jkl"), "abc is not a data frame\\.") + expect_error(summary_graph(iris, "def", "ghi", "jkl"), "def does not appear to be a column of data\\. Please check input\\.") + expect_error(summary_graph(iris, Species, "ghi", "jkl"), "Species is not a numeric variable\\.") + expect_error(summary_graph(iris, Petal.Length, 'Species', 123), "resp_units must be provided as a string with quotes\\.") + expect_error(summary_graph(mtcars, mpg, c("cyl", "vs", "am", "gear"), "abc"), "Additional explanatory variables are not currently supported\\.") +}) diff --git a/tests/testthat/test-utility_functions.R b/tests/testthat/test-utility_functions.R index 8211767..b9aa281 100644 --- a/tests/testthat/test-utility_functions.R +++ b/tests/testthat/test-utility_functions.R @@ -12,3 +12,9 @@ test_that("Output prints if crayon is not installed", { local_mocked_bindings(is_installed = function(...) FALSE) expect_output(print(biometryassist:::.onAttach(pkg = "biometryassist"))) }) + +test_that("Warning prints if cran version is newer", { + rlang::local_interactive(value = TRUE) + local_mocked_bindings(compare_version = function(...) 1L) + expect_warning(print(biometryassist:::.onAttach(pkg = "biometryassist"))) +})