simp2bary: Barycentric coordinates

simp2baryR Documentation

Barycentric coordinates

Description

Convert points on the two-dimensional probability simplex (embedded in R3) to points on the triangle in R2. These are often used in what is also called ternary plots.

Usage

proj_mat

simp2bary(v, simplify = TRUE)

bary2simp(v, simplify = TRUE)

simplex_mesh(delta)

Arguments

v

a numeric 3-vector or nx3 matrix; in the latter case, the function is applied to the rows

simplify

simplify the result to numeric vector?

delta

the mesh size

Format

An object of class matrix (inherits from array) with 2 rows and 2 columns.

Examples


simp2bary(c(1,0,0))
simp2bary(c(0,1,0))
simp2bary(c(0,0,1))

bary2simp(c(0,0))
bary2simp(c(1,0))
bary2simp(c(1/2, sqrt(3)/2))

samples <- rdirichlet(5, rep(1,3))
simp2bary(samples)

library(dplyr)
library(ggplot2); theme_set(theme_bw())

rdirichlet(1e3, rep(1,3)) %>% simp2bary %>% 
  as.data.frame %>% tbl_df %>% 
  ggplot(aes(V1, V2)) +
    geom_point() +
    coord_equal()

simplex_mesh(.05) %>% as.data.frame %>% tbl_df %>% 
  ggplot(aes(x, y)) + geom_point() +
    coord_equal()

simplex_mesh(.01) %>% as.data.frame %>% tbl_df %>% 
  ggplot(aes(x, y)) + geom_point(size = .1) +
    coord_equal()
    
simplex_mesh(.005) %>% as.data.frame %>% tbl_df %>% 
  ggplot(aes(x, y)) + geom_point(size = .001) +
    coord_equal()

simplex_mesh(.005) %>% as.data.frame %>% tbl_df %>% 
  ggplot(aes(x, y)) + geom_tile() +
    coord_equal()

bary2simp(simplex_mesh(.1))
rowSums(bary2simp(simplex_mesh(.1)))


dkahle/dirichlet documentation built on June 4, 2023, 4:51 a.m.