jeudi 10 février 2022

How to plot multiple samples on ggplot in R?

I've run a for loop and taken multiple samples of data. I want to take the data I just got and turn in into a histogram using ggplot.

Here is my code:

for (i in 1:1000){
  sample[1000]
  sample[i] <- mean(pop$y[sample.int(nrow(pop),5, replace = FALSE)])
  
}

ggplot(sample, aes(x = sample)) + geom_histogram(bins = 40)

I get this error message: "Error: data must be a data frame, or other object coercible by fortify(), not a numeric vector. Run rlang::last_error() to see where the error occurred."

Is there a way for me to take the sample array I have now and turn it into a histogram using ggplot? Anything helps. Thanks!




Aucun commentaire:

Enregistrer un commentaire