**Hi,**

**I've a problem with an exercise of RStudio:**

**Generate three samples of size n = {10, 1000, 100,000} from the random variable**

**X ∼ N (PN, 1) and plot the corresponding histograms**

**I've already done the Gaussian curve:**

x <- seq(11,19,0.1)

g <- plot(x, dnorm(x, mean=15, sd=1, log=FALSE), main="f(x)", xlab="x", ylab="g(x)", abline(v=15))

**I've also tried to make the histogram, but the problem is that it gives a result without taking care of probabilities of the gaussian curve:**

op <- par(mfrow=c(3,1))

hist(sample(x, size=10, replace=TRUE, prob=NULL), xlim=range(11:19), main="Size 10", xlab="x")

hist(sample(x, size=1000, replace=TRUE, prob=NULL), xlim=range(11:19), main="Size 100", xlab="x")

hist(sample(x, size=100000, replace=TRUE, prob=NULL), xlim=range(11:19), main="Size 100000", xlab="x")

**Any Idea?**

Could you a bit more precise in what you mean by "...result without taking care of probabilities of the gaussian curve"?

It looks like you're plotting just a uniform distribution from:

```
x <- seq(11,19,0.1)
x
#> [1] 11.0 11.1 11.2 11.3 11.4 11.5 11.6 11.7 11.8 11.9 12.0 12.1 12.2 12.3
#> [15] 12.4 12.5 12.6 12.7 12.8 12.9 13.0 13.1 13.2 13.3 13.4 13.5 13.6 13.7
#> [29] 13.8 13.9 14.0 14.1 14.2 14.3 14.4 14.5 14.6 14.7 14.8 14.9 15.0 15.1
#> [43] 15.2 15.3 15.4 15.5 15.6 15.7 15.8 15.9 16.0 16.1 16.2 16.3 16.4 16.5
#> [57] 16.6 16.7 16.8 16.9 17.0 17.1 17.2 17.3 17.4 17.5 17.6 17.7 17.8 17.9
#> [71] 18.0 18.1 18.2 18.3 18.4 18.5 18.6 18.7 18.8 18.9 19.0
```

Created on 2018-04-11 by the reprex package (v0.2.0).

Do you maybe want to do something like this?

```
op <- par(mfrow=c(3,1))
hist(rnorm(10, mean=15, sd=1), xlim=range(11:19), main="Size 10", xlab="x")
hist(rnorm(100, mean=15, sd=1), xlim=range(11:19), main="Size 100", xlab="x")
hist(rnorm(10000, mean=15, sd=1), xlim=range(11:19), main="Size 100000", xlab="x")
```

Also just a small note, it's usually nice to format your code up with markdown. FAQ: How to format your code

If you want to save time, check out the `reprex`

package.

1 Like

Okey, the real question is:

How can I plot a line on the histogram?

I mean... a line that shows that the histogram is a gaussian function?