segment.region: Divide a region into equal parts.

Description Usage Arguments Value Examples

View source: R/segment.region.R

Description

This function is useful for placing a given number of elements into a constrained space on a plot. It returns coordinates for the desired number of points in the given region. The points can either be centered within the region or flush to the ends.

Usage

1
segment.region(region.min, region.max, num.points, alignment = c("center", "ends"))

Arguments

region.min

A numerical value indicating the minimum value of the region.

region.max

A numerical value indicating the maximum value of the region.

num.points

The number of points to place in the region.

alignment

A character element indicating whether the points should be centered within the region or whether they should extend to the ends of the region.

Value

A vector of coordinates is returned specifying the coordinates at which points should be plotted to be evenly distributed in the region.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
num.points <- 5
coords.1 <- segment.region(region.min = 5, region.max = 7, 
num.points = num.points, alignment = c("ends"))
coords.2 <- segment.region(region.min = 5, region.max = 7, 
num.points = num.points, alignment = c("center"))
plot(x = coords.1, y = rep(0.25, num.points), xlim = c(4,8), 
ylim = c(0,1),col = "blue", pch = 16, xlab = "", ylab = "", 
axes = FALSE)
points(x = coords.2, y = rep(0.75, num.points), xlim = c(4,8), 
ylim = c(0,1),col = "purple", pch = 16)
abline(v = 5); abline(v = 7); axis(1)

cape documentation built on May 29, 2017, 4:49 p.m.