1

I'm just trying to illustrate Central Limit Theorem by taking the mean of random samples of different prob. distributions. I have the following code, in which I increase the sample size of an exponential distribution.

set.seed(12577) # for reproducability
n <- 50 
lambda <- 0.2  
out <-  rexp(5000, lambda)
for(i in seq_along(sample_size)) {
  out <- cbind(out, c(replicate(sample_size[i], mean(rexp(n, lambda))) , rep(NA, 5000 - sample_size[i] )))
}
out <- as.data.frame(out)
names(out) <- c("EXP_SAMPLE_5000", paste0("RND_SAMPLE_", sample_size))

I would like to use ggvis, to selecting different columns to create histograms. I'm trying the following but is not working:

out %>%  ggvis(x = input_select(label = "Choose what to plot:",
                                choices = names(out),
                                selected = "EXP_SAMPLE_5000",
                                map = as.name)) %>% layer_histograms()

UPDATE: Following the comments of @Martin Schmelzer, I added the dummy but now the histogram doesn't make sense.

out %>%  ggvis(x = ~ 100, y = input_select(label = "Choose what to plot:",
                                choices = names(out),
                                #multiple=TRUE,
                                map = as.name)) %>% layer_histograms()
Mario GS
  • 859
  • 8
  • 22

0 Answers0