Libraries for plotting

library("ggplot2")
library("dplyr")

Data

your data is the my_data object; I use iris here just for an example. the target_dist is the distribution that I am trying to match, replicate, test against, etc… depending on what you are doing with these data. The important part is that you have a target distribution family, normal in this case and parameters to draw from that distribution, here mean = 6 and sd = 0.75. The family and paramers you chose will be explicity decided upon or modeled based on what you are trying to achieve. Make sure lots of though goes into that part.

my_data <- iris$Sepal.Length
target_dist <- rnorm(10000,6,0.75)

Quick plot

hist(my_data)

hist(target_dist)

Combine data

One way to plot this is to put the data into a long format with one column for the data values and one to say which distribution sample they come from.

plot_data <- data.frame(data   = c(my_data, target_dist),
                        sample = rep(c("empirical","reference"),
                                   times = c(length(my_data),
                                             length(target_dist))))

Plot

Here are two ways to plot this. They are not the prettiest and probably better ways, but they are a start. The first one plots both as a density and the second plots the target as a density and empirical as a histogram.

ggplot(plot_data, aes(x = data, color = sample)) +
  geom_density() +
  theme_minimal()

or

ggplot() +
  geom_histogram(data = dplyr::filter(plot_data, sample == "empirical"),
                 aes(x = data, ..density..), color = "gray50") +
  geom_density(data = dplyr::filter(plot_data, sample == "reference"),
             aes(x = data), color = "red") +
  theme_minimal()
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.