Hi,
I wanted to generate a random sample, plot it on a histogram, add a normal distribution to the background, but got the error message:
*Error in dnorm(mean = mu, sd = sigma) : *
- argument "x" is missing, with no default*
Code was the following:
mu <- 5
sigma <- 1
n <- 10
ntraject <- 500
random_matrix <- rnorm(n * ntraject, mean = mu, sd = sigma) %>%
matrix(nrow = n, ncol = ntraject) %>%
tibble()
ggplot(data = data.frame(x=colMeans(random_matrix)),aes(x=x)) +
stat_function(fun=dnorm(mean = mu, sd = sigma), geom = "area", alpha = .3) +
geom_histogram(color = "black")
(If I ignore the line "stat_function...", then it works fine, for the histogram)
Thank you for your help in advance,
MarcellGranat