1

The below snippet is not working when I use the manipulate() function. Only the chart appears for initial value of the slider but the control does not appear. I use a plot() function, the control appears.

library(UsingR)
data(galton)
myHist <- function(mu){
    mse <- mean((galton$child - mu)^2)
    g <- ggplot(galton, aes(x = child)) + geom_histogram(fill = "salmon", colour = "black", binwidth=1) +
        geom_vline(xintercept = mu, size = 3) +
        ggtitle(paste("mu = ", mu, ", MSE = ", round(mse, 2), sep = ""))
    g
}
manipulate(myHist(mu), mu = slider(62, 74, step = 0.5))
Colibri
  • 682
  • 6
  • 8

1 Answers1

1

It is related to ggplot. Not with the code.

It happened to me. But if I use another example before, with a base plot, it is fixed. That is, after it works with the base plot, it works for me with ggplot. For example:

f <- function(disp) {
 set.seed(1516)
 plot(density(x = rnorm(n = 40000, mean = 15, sd = disp), 
      from = 0, to = 30))
}

manipulate(f(disp), dispersion = slider(min = 0.5, 
                max = 4, initial = 2, step = 0.5, 
                label = 'Est. Dev.'))
Colibri
  • 682
  • 6
  • 8
  • This just happened to me as well. Interesting that manipulate used to work with ggplot2. But not anymore. Thanks. I wonder if it is just manipulate is being faded out for something else. – Jose R Apr 09 '23 at 19:14