# Example 1: plot an adaptive histogram from data generated by
# a Gaussian mixture model with three components
x <- c(rnorm(40, mean=-2, sd=0.3),
rnorm(45, mean=1, sd=0.1),
rnorm(70, mean=3, sd=0.2))
ahist(x, col="lightblue", sub=paste("n =", length(x)),
col.stick="salmon", lwd=2,
main=paste("Example 1. Gaussian mixture model with 3 components",
"(one bin per component)", sep="\n"))
# Example 2: plot an adaptive histogram from data generated by
# a Gaussian mixture model with three components using a given
# number of bins
ahist(x, k=9, col="lavender", col.stick="salmon",
sub=paste("n =", length(x)), lwd=2,
main=paste("Example 2. Gaussian mixture model with 3 components",
"(on average 3 bins per component)", sep="\n"))
# Example 3: The DNase data frame has 176 rows and 3 columns of
# data obtained during development of an ELISA assay for the
# recombinant protein DNase in rat serum.
data(DNase)
res <- Ckmeans.1d.dp(DNase$density)
kopt <- length(res$size)
ahist(res, data=DNase$density, col=rainbow(kopt),
col.stick=rainbow(kopt)[res$cluster],
sub=paste("n =", length(x)), border="transparent",
xlab="Optical density of protein DNase",
main="Example 3. Elisa assay of DNase in rat serum")
# Example 4: Add sticks to histograms with the R provided
# hist() function.
ahist(DNase$density, breaks="Sturges", col="palegreen",
add.sticks=TRUE, col.stick="darkgreen",
main=paste("Example 4. Elisa assay of DNase in rat serum",
"(Equal width bins)", sep="\n"),
xlab="Optical density of protein DNase")
# Example 5: Weighted adatpive histograms
x <- sort(c(rnorm(40, mean=-2, sd=0.3),
rnorm(45, mean=2, sd=0.1),
rnorm(70, mean=4, sd=0.2)))
y <- (1 + sin(0.10 * seq_along(x))) * (x-1)^2
ahist(x, weight=y, sub=paste("n =", length(x)),
col.stick="forestgreen", lwd.stick=0.25, lwd=2,
main="Example 5. Weighted adaptive histogram")
# Example 6: Cluster data with repetitive elements
ahist(c(1,1,1,1, 3,4,4, 6,6,6), k=c(2,4), col="gray",
lwd=2, lwd.stick=6, col.stick="chocolate",
main=paste("Example 6. Adaptive histogram of",
"repetitive elements", sep="\n"))
Run the code above in your browser using DataLab