This is an R Markdown document created with examples of how to work with manipulate. Based on Coursera’s Data Products course.
If you input this:
library(manipulate)
manipulate(plot(1:x), x=slider(1,100))
You will obtain the following figure on Rstudio, where you can move around the slider (the more you go to the right, the more points will be plotted):
library(manipulate)
library(UsingR)
myHist <- function (mu) {
hist (galton$child,col="blue" ,breaks= 100)
lines(c(mu, mu), c(0, 150), col= "red", lwd= 5)
mse <- mean((galton$child - mu)^2)
text(63, 150, paste ("mu = ", mu))
text(63, 140, paste ("MSE = ", round (mse, 2)))
}
manipulate(myHist(mu), mu=slider (62, 74, step = 0.5))
Again you will get a slider:
Cool stuff to try:
manipulate(
barplot(as.matrix(longley[,factor]),
beside = TRUE, main = factor),
factor = picker("GNP", "Unemployed", "Employed"))
manipulate(
boxplot(Freq ~ Class, data = Titanic, outline = outline),
outline = checkbox(FALSE, "Show outliers"))
manipulate(
plot(cars, xlim = c(0, x.max), type = type, ann = label),
x.max = slider(10, 25, step=5, initial = 25),
type = picker("Points" = "p", "Line" = "l", "Step" = "s"),
label = checkbox(TRUE, "Draw Labels"))