flip.coin(faces = 2, prob, border = "white", grid = "white",
col = 1:2, type = "p", pch = 21, bg = "transparent", digits = 3)
NULL
, each face will be shown in the same probability.points
.faces
is a single integer, say 2, a sequence of integers from 1
to faces
will be used to denote the faces of a coin; otherwise this
character vector just gives the names of each face.
When the $i$-th face shows up, a colored thin rectangle will be added
to the corresponding place (the $i$-th bar), and there will be
corresponding annotations for the number of tosses and frequencies.
The special argument grid
is for consideration of a too large number
of flipping, in which case if you still draw horizontal lines in these
rectangles, the rectangles will be completely covered by these lines, thus
we should specify it as NA
.
At last the frequency for each face will be computed and shown in
the header of the plot -- this shall be close to prob
if
ani.options('nmax')
is large enough.points
, sample
oopt = ani.options(interval = 0.2, nmax = ifelse(interactive(),
100, 2))
## a coin would stand on the table?? just kidding :)
flip.coin(faces = c("Head", "Stand", "Tail"), type = "n",
prob = c(0.45, 0.1, 0.45), col = c(1, 2, 4))
flip.coin(bg = "yellow")
## HTML animation page
saveHTML({
ani.options(interval = 0.2, nmax = ifelse(interactive(),
100, 2))
par(mar = c(2, 3, 2, 1.5), mgp = c(1.5, 0.5, 0))
flip.coin(faces = c("Head", "Stand", "Tail"), type = "n",
prob = c(0.45, 0.1, 0.45), col = c(1, 2, 4))
}, img.name = "flip.coin", htmlfile = "flip.coin.html", ani.height = 500,
ani.width = 600, title = "Probability in flipping coins",
description = c("This animation has provided a simulation of flipping coins",
"which might be helpful in understanding the concept of probability."))
ani.options(oopt)
Run the code above in your browser using DataLab