Skip to content

Commit

Permalink
Add plot method for CompositionMatrix
Browse files Browse the repository at this point in the history
  • Loading branch information
nfrerebeau committed Nov 16, 2023
1 parent c5a1de4 commit 57233ad
Show file tree
Hide file tree
Showing 12 changed files with 529 additions and 4 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@ Imports:
dimensio (>= 0.4.0),
graphics,
grDevices,
isopleuros (>= 1.0.0),
methods,
MASS,
stats,
utils
Suggests:
folio,
igraph,
isopleuros,
knitr,
rmarkdown,
rsvg,
Expand Down
2 changes: 2 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -93,3 +94,4 @@ importFrom(stats,var)
importFrom(utils,combn)
importFrom(utils,tail)
importMethodsFrom(dimensio,pca)
importMethodsFrom(isopleuros,ternary_pairs)
17 changes: 17 additions & 0 deletions R/AllGenerics.R
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
1 change: 1 addition & 0 deletions R/nexus-package.R
Original file line number Diff line number Diff line change
Expand Up @@ -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<-
Expand Down
12 changes: 12 additions & 0 deletions R/plot.R
Original file line number Diff line number Diff line change
Expand Up @@ -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, ...,
Expand Down
6 changes: 6 additions & 0 deletions inst/examples/ex-plot.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
## Coerce to compositional data
data("hongite")
coda <- as_composition(hongite)

## Ternary plots
plot(coda)
432 changes: 432 additions & 0 deletions inst/tinytest/_tinysnapshot/plot_pairs.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions inst/tinytest/test_plot.R
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
3 changes: 2 additions & 1 deletion man/as_graph.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion man/barplot.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

48 changes: 48 additions & 0 deletions man/plot.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion man/plot_logratio.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 57233ad

Please sign in to comment.