diff --git a/DESCRIPTION b/DESCRIPTION index f1e3cc3..c51d2dc 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -27,6 +27,7 @@ Imports: dimensio (>= 0.4.0), graphics, grDevices, + isopleuros (>= 1.0.0), methods, MASS, stats, @@ -34,7 +35,6 @@ Imports: Suggests: folio, igraph, - isopleuros, knitr, rmarkdown, rsvg, diff --git a/NAMESPACE b/NAMESPACE index 915a597..a9da9a7 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -9,6 +9,7 @@ S3method(dist,CompositionMatrix) S3method(mahalanobis,CompositionMatrix) S3method(mahalanobis,ILR) S3method(mean,CompositionMatrix) +S3method(plot,CompositionMatrix) S3method(plot,LogRatio) S3method(plot,OutlierIndex) export(remove_NA) @@ -93,3 +94,4 @@ importFrom(stats,var) importFrom(utils,combn) importFrom(utils,tail) importMethodsFrom(dimensio,pca) +importMethodsFrom(isopleuros,ternary_pairs) diff --git a/R/AllGenerics.R b/R/AllGenerics.R index c02f4d7..f0d4b03 100644 --- a/R/AllGenerics.R +++ b/R/AllGenerics.R @@ -808,6 +808,23 @@ NULL #' @rdname barplot NULL +#' Plot Compositional Data +#' +#' Displays a matrix of ternary plots. +#' @param x A [`CompositionMatrix-class`] object. +#' @inheritParams isopleuros::ternary_pairs +#' @return +#' `plot()` is called for its side-effects: is results in a graphic being +#' displayed (invisibly return `x`). +#' @seealso [isopleuros::ternary_pairs()], [isopleuros::ternary_plot()] +#' @example inst/examples/ex-plot.R +#' @author N. Frerebeau +#' @docType methods +#' @family plot methods +#' @name plot +#' @rdname plot +NULL + #' Plot Log-Ratios #' #' Displays a density plot. diff --git a/R/nexus-package.R b/R/nexus-package.R index 62d71fd..a64d8a8 100644 --- a/R/nexus-package.R +++ b/R/nexus-package.R @@ -42,6 +42,7 @@ #' @import arkhe #' @importMethodsFrom dimensio pca +#' @importMethodsFrom isopleuros ternary_pairs #' @importFrom grDevices hcl.colors #' @importFrom methods as as<- callGeneric callNextMethod #' .hasSlot initialize is new setClass setGeneric setMethod slot slot<- diff --git a/R/plot.R b/R/plot.R index d5fec1e..750db45 100644 --- a/R/plot.R +++ b/R/plot.R @@ -3,6 +3,18 @@ NULL # CompositionMatrix ============================================================ +#' @export +#' @method plot CompositionMatrix +plot.CompositionMatrix <- function(x, ..., margin = NULL) { + isopleuros::ternary_pairs(x, margin = margin, ...) + invisible(x) +} + +#' @export +#' @rdname plot +#' @aliases plot,CompositionMatrix-method +setMethod("plot", c(x = "CompositionMatrix"), plot.CompositionMatrix) + #' @export #' @method barplot CompositionMatrix barplot.CompositionMatrix <- function(height, ..., diff --git a/inst/examples/ex-plot.R b/inst/examples/ex-plot.R new file mode 100644 index 0000000..002a54b --- /dev/null +++ b/inst/examples/ex-plot.R @@ -0,0 +1,6 @@ +## Coerce to compositional data +data("hongite") +coda <- as_composition(hongite) + +## Ternary plots +plot(coda) diff --git a/inst/tinytest/_tinysnapshot/plot_pairs.svg b/inst/tinytest/_tinysnapshot/plot_pairs.svg new file mode 100644 index 0000000..05a6de6 --- /dev/null +++ b/inst/tinytest/_tinysnapshot/plot_pairs.svg @@ -0,0 +1,432 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +A +B +* + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +A +C +* + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +A +D +* + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +A +E +* + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +B +C +* + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +B +D +* + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +B +E +* + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +C +D +* + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +C +E +* + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +D +E +* + + + + + + + +A + + + + + + + +B + + + + + + + +C + + + + + + + +D + + + + + + + +E + + + + + + + + + diff --git a/inst/tinytest/test_plot.R b/inst/tinytest/test_plot.R index 3b9a9a9..9627c3e 100644 --- a/inst/tinytest/test_plot.R +++ b/inst/tinytest/test_plot.R @@ -9,6 +9,10 @@ if (at_home()) { data("hongite") coda <- as_composition(hongite) + # Plot ======================================================================= + plot_pairs <- function() plot(coda, order = NULL) + expect_snapshot_plot(plot_pairs, "plot_pairs") + # Barplot ==================================================================== plot_barplot <- function() barplot(coda, order = NULL) expect_snapshot_plot(plot_barplot, "plot_barplot") diff --git a/man/as_graph.Rd b/man/as_graph.Rd index 5080a8b..c30b89a 100644 --- a/man/as_graph.Rd +++ b/man/as_graph.Rd @@ -57,7 +57,8 @@ plot(plr_graph) \seealso{ Other plot methods: \code{\link{barplot}()}, -\code{\link{plot_logratio}} +\code{\link{plot_logratio}}, +\code{\link{plot}()} } \author{ N. Frerebeau diff --git a/man/barplot.Rd b/man/barplot.Rd index 991d726..f840dee 100644 --- a/man/barplot.Rd +++ b/man/barplot.Rd @@ -77,7 +77,8 @@ barplot(coda, order = 1, horiz = FALSE, main = "Kommos Ceramics") \seealso{ Other plot methods: \code{\link{as_graph}()}, -\code{\link{plot_logratio}} +\code{\link{plot_logratio}}, +\code{\link{plot}()} } \author{ N. Frerebeau diff --git a/man/plot.Rd b/man/plot.Rd new file mode 100644 index 0000000..cb085e6 --- /dev/null +++ b/man/plot.Rd @@ -0,0 +1,48 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/AllGenerics.R, R/plot.R +\docType{methods} +\name{plot} +\alias{plot} +\alias{plot,CompositionMatrix,ANY-method} +\alias{plot,CompositionMatrix-method} +\title{Plot Compositional Data} +\usage{ +\S4method{plot}{CompositionMatrix,ANY}(x, ..., margin = NULL) +} +\arguments{ +\item{x}{A \code{\linkS4class{CompositionMatrix}} object.} + +\item{...}{Further \link[graphics:par]{graphical parameters}.} + +\item{margin}{A \code{\link{character}} string or an \code{\link{integer}} giving the index of +the column to be used as the third part of the ternary plots. If \code{NULL} +(the default), marginal compositions will be used (i.e. the geometric mean +of the non-selected parts).} +} +\value{ +\code{plot()} is called for its side-effects: is results in a graphic being +displayed (invisibly return \code{x}). +} +\description{ +Displays a matrix of ternary plots. +} +\examples{ +## Coerce to compositional data +data("hongite") +coda <- as_composition(hongite) + +## Ternary plots +plot(coda) +} +\seealso{ +\code{\link[isopleuros:ternary_pairs]{isopleuros::ternary_pairs()}}, \code{\link[isopleuros:ternary_plot]{isopleuros::ternary_plot()}} + +Other plot methods: +\code{\link{as_graph}()}, +\code{\link{barplot}()}, +\code{\link{plot_logratio}} +} +\author{ +N. Frerebeau +} +\concept{plot methods} diff --git a/man/plot_logratio.Rd b/man/plot_logratio.Rd index 7bf4e3f..786d288 100644 --- a/man/plot_logratio.Rd +++ b/man/plot_logratio.Rd @@ -90,7 +90,8 @@ plot(clr, flip = TRUE) \seealso{ Other plot methods: \code{\link{as_graph}()}, -\code{\link{barplot}()} +\code{\link{barplot}()}, +\code{\link{plot}()} } \author{ N. Frerebeau