Skip to content

Commit

Permalink
2.3.2.9000: plot c(0,0,0) at origin
Browse files Browse the repository at this point in the history
  • Loading branch information
ms609 committed Aug 5, 2024
1 parent cb4afbb commit a8b3285
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 4 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Package: Ternary
Version: 2.3.2
Version: 2.3.2.9000
Title: Create Ternary and Holdridge Plots
Description: Plots ternary diagrams (simplex plots / Gibbs triangles) and
Holdridge life zone plots <doi:10.1126/science.105.2727.367> using the
Expand Down
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Ternary v2.3.2.9000 (development)
- Support plotting of `c(0, 0, 0)`, at origin.

# Ternary v2.3.2 (2024-07-25)
- Document reading data into R in vignette for new users.
- Provide package anchors in documentation pages.
Expand Down
8 changes: 6 additions & 2 deletions R/Coordinates.R
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,17 @@ TernaryToXY.numeric <- function(
c(3, 2, 1),
c(2, 3, 1)
)]
if (!any(as.logical(abc))) {
# abc == c(0, 0, 0)
abc <- c(1, 1, 1)
}

x_deviation <- abc[3] / sum(abc)
x_deviation <- abc[[3]] / sum(abc)
if (x_deviation == 1) {
x <- cos(pi / 6)
y <- 0
} else {
y_deviation <- (abc[1] - abc[2]) / sum(abc[1:2])
y_deviation <- (abc[[1]] - abc[[2]]) / sum(abc[1:2])
x <- x_deviation * cos(pi / 6)
y <- y_deviation * (1 - x_deviation) / 2
}
Expand Down
2 changes: 1 addition & 1 deletion inst/TernaryApp
Submodule TernaryApp updated 1 files
+1 −1 app.R
4 changes: 4 additions & 0 deletions tests/testthat/test-Coordinates.R
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,10 @@ test_that("OutsidePlot() works", {
expect_true(OutsidePlot(0, 0.8, tolerance = 0.05))
})

test_that("Corner cases are correct", {
expect_equal(TernaryToXY(c(0, 0, 0)), TernaryToXY(c(2, 2, 2)))
})

test_that("Errors are handled nicely", {
expect_error(TernaryCoords(1:3, direction = 5))
expect_error(TernaryXRange(direction = 5))
Expand Down

0 comments on commit a8b3285

Please sign in to comment.