Skip to content

Instantly share code, notes, and snippets.

@primaryobjects
Last active February 3, 2016 02:21
Show Gist options
  • Save primaryobjects/c68b98f3fabda703575a to your computer and use it in GitHub Desktop.
Save primaryobjects/c68b98f3fabda703575a to your computer and use it in GitHub Desktop.
Using manipulate on R chart to create an interactive chart.
## Including the required R packages.
packages <- c('manipulate', 'UsingR')
if (length(setdiff(packages, rownames(installed.packages()))) > 0) {
install.packages(setdiff(packages, rownames(installed.packages())))
}
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 = ', mse))
}
manipulate(myHist(mu), mu = slider(62, 74, step = 0.5))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment