Last active
February 3, 2016 02:21
-
-
Save primaryobjects/c68b98f3fabda703575a to your computer and use it in GitHub Desktop.
Using manipulate on R chart to create an interactive chart.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## 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