quincunx: Demonstration of the Quincunx (Bean Machine/Galton Box)

Description Usage Arguments Details Value Note Author(s) See Also

View source: R/quincunx.R


Simulates the quincunx with “balls” (beans) falling through several layers (denoted by triangles) and the distribution of the final locations at which the balls hit is denoted by a histogram; quincunx() is shows single layer, and quincunx2() is a two-stage version of the quincunx.


quincunx(balls = 200, layers = 15, pch.layers = 2, pch.balls = 19, 
    col.balls = sample(colors(), balls, TRUE), cex.balls = 2)

quincunx2(balls = 200, layers = 15, pch.layers = 2, pch.balls = 19, 
    col.balls = sample(colors(), balls, TRUE), cex.balls = 2)



number of balls


number of layers


point character of layers; triangles (pch = 2) are recommended

pch.balls, col.balls, cex.balls

point character, colors and magnification of balls


The bean machine, also known as the quincunx or Galton box, is a device invented by Sir Francis Galton to demonstrate the law of error and the normal distribution.

When a ball falls through a layer, it can either go to the right or left side with the probability 0.5. At last the location of all the balls will show us the bell-shaped distribution.


A named vector: the frequency table for the locations of the balls. Note the names of the vector are the locations: 1.5, 2.5, ..., layers - 0.5.


The maximum number of animation frames is controlled by ani.options('nmax') as usual, but it is strongly recommended that ani.options(nmax = balls + layers -2), in which case all the balls will just fall through all the layers and there will be no redundant animation frames.


Yihui Xie, Lijia Yu, and Keith ORourke

See Also


animation documentation built on May 19, 2017, 8:08 a.m.

Search within the animation package
Search all R packages, documentation and source code

Questions? Problems? Suggestions? Tweet to @rdrrHQ or email at ian@mutexlabs.com.

Please suggest features or report bugs in the GitHub issue tracker.

All documentation is copyright its authors; we didn't write any of that.