# NOT RUN {
plot.hist <- function(panel) {
with(panel, {
xlim <- range(c(x, mean(x) + c(-3, 3) * sd(x)))
if (panel$cbox[3])
clr <- "lightblue" else clr <- NULL
hist(x, freq = FALSE, col = clr, xlim = xlim)
if (panel$cbox[1]) {
xgrid <- seq(xlim[1], xlim[2], length = 50)
dgrid <- dnorm(xgrid, mean(x), sd(x))
lines(xgrid, dgrid, col = "red", lwd = 3)
}
if (panel$cbox[2])
box()
})
panel
}
x <- rnorm(50)
panel <- rp.control(x = x)
rp.checkbox(panel, cbox, plot.hist,
labels = c("normal density", "box", "shading"), title = "Options")
rp.do(panel, plot.hist)
# }
Run the code above in your browser using DataLab