Learn R Programming

trifield (version 1.0)

ternary.grid: Constructs a ternary grid

Description

The function builds a rectangular lattice of points bounded by an equilateral triangle with unit altitude. It can be used with ternary.apply and ternary.field to create a surface of values for plotting.

Usage

ternary.grid(grid.size)

Arguments

grid.size
The number of rows and columns in the grid

Value

  • Data frame with columns
  • xx-coordinate
  • yy-coordinate
  • xicolumn indices (I think)
  • yirow indices (I think)
  • adistance along first ternary axis
  • bdistance along second ternary axis
  • cdistance along third ternary axis

Details

The size of the grid is the number of rows and colunn in the rectangular region bounding the ternary plot region. The number of output x, y and corresponding a, b, c points will be less than rows times columns because many x, y points fall outside the ternary region. In all cases, the sum of a, b and c will be unity.

See Also

link{ternary.apply}, link{ternary.grid}

Examples

Run this code
## The function is currently defined as
function(grid.size)
{
	lx = 2 / sqrt(3)
	nx = trunc(lx * grid.size)
	ny = grid.size
	x = seq(0, lx, length = nx)
	y = seq(0, 1, length = ny)
	xy = as.matrix(expand.grid(x = x, y = y))
	xyi = as.matrix(expand.grid(x = 1:nx, y = 1:ny))
	abc = xy2abc(xy)
	i = rowSums(abc < 0) == FALSE
	abc = abc[i,]
	xy = xy[i,]	
	xyi = xyi[i,]
	res = data.frame(xy, xyi, abc)
	names(res) = c('x', 'y', 'xi', 'yi', 'a', 'b', 'c')
	res
  }

Run the code above in your browser using DataLab