How to generate a random sample and distribute values based in an probability distribution?
Create some random data
df &lt;- data.frame(
  cat_cols = c(rep(&quot;A&quot;, 200), rep(&quot;B&quot;,150)),
  cont_vals = c(rnorm(200, 20, 5), rnorm(150,25,10)))
# Set desired binwidth and number of non-missing obs
bw = 2
n_obs = sum(!is.na(df$cont_vals))

Now plot it
library(ggplot2)
ggplot(df, aes(cont_vals))  + 
  geom_histogram(aes(y = ..density..), binwidth = bw, colour = &quot;black&quot;) + 
  stat_function(fun = dnorm, args = list(mean = mean(df$cont_vals), sd = sd(df$cont_vals)))