% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/midp2brk.R
\name{midp2brk}
\alias{midp2brk}
\title{Define Break Points from Midpoints}
\usage{
midp2brk(midpoints, min = NULL, max = NULL, margin = NULL)
}
\arguments{
\item{midpoints}{a vector of midpoints.}

\item{min}{value of the lowest break.}

\item{max}{value of the highest break.}

\item{margin}{value to be subtracted/added to
the lowest and highest midpoints. \cr
default margin = ( midpoints[2]-midpoints[1] )/2}
}
\value{
A vector of break points of length length(midpoints)+1.
}
\description{
Define Break Points from Midpoints
}
\details{
Break values from midpoint values: \cr
 \code{brk[1]=midp[1] - margin}\cr
 \code{brk[2]=midp[1] + (midp[2]-midp[1])/2} \cr
 \code{brk[3]=midp[2] + (midp[3]-midp[2])/2} \cr
 \code{brk[length(midpoints)+1]=midp[length(midpoints)] + margin} \cr
 where \code{margin=(midp[2]-midp[1])/2}. \cr
 In general, the break point is located at the center of two midpoints:\cr
 \code{brk[k]=0.5*(midp[k-1]+midp[k])}
 \cr

Midpoint values from break values: \cr
 \code{midp[1]=0.5*(brk[1]+brk[2])} or {midp[1]=min}\cr
 \code{midp[2]=0.5*(brk[2]+brk[3])} \cr
 \code{midp[3]=2*brk[3]-midp[2]} \cr
 \code{brk[length(brk)-1]=2*brk[length(brk)-1]-midp[length(brk)-2]} \cr
\cr
Note that midp[1] is treated separately and it is assumed that
the break point is located at the center of two midpoints.
\cr\cr
Try below to see how the obs on the border are classified. \cr
   \code{ xx <- c(1,2,3,4,5,6,7) } \cr
   \code{ brks <- c(0,2,4,6,8) } \cr
   \code{ cc1 <- cut(xx,brks) } \cr
   \code{ cc2 <- cut(xx,brks, right=FALSE) } \cr
   \code{ Print(xx,as.character(cc1),as.character(cc2)) }\cr
}
\examples{
midp <- seq(0,5,length.out=11)
brk <- midp2brk( midp, margin=1 )
Print(midp,brk)

midp <- seq(0,5,length.out=11)
brk <- midp2brk( midp, margin=1 )
Print(midp,brk)

set.seed(1701)
x <- rnorm(100)+2.5

# histogram by native hist
resh <- hist( x, breaks=brk )

# histogram by native barplot
# freq <- resh$counts
# names(freq) <- midp
# barplot( freq, space=0 )
barplot( resh$count,names.arg=midp, space=0, xlab="X", col="white"
        , sub="top and bottom bars contain outliers." )

# Below causes error because 'brk' does not span the range of 'x'.
# brk <- midp2brk( midp )
# resh <- hist( x, breaks=brk )

}
