

Using coord_flip plots back-to-back histograms horizontally. We see that ggplot doesn't like stacking when you have negative data, but it's ok for this exmaple and don't overlap. flips the second histogram around zero so that they are back-to-back. This just scales the histogram to a density and not a count. density call in the aes for the histograms. I simply simulated 2 normal distributions of 100 points and then plotted them. # Warning: Stacking not well defined when ymin != 0 Geom_histogram( aes(x = x2, y = -.density.), binwidth = diff(range(df$x))/30, fill= "green") G = ggplot(df, aes(x)) + geom_histogram( aes(x = x, y =. I provide the code below because some have different preferences.) ggplot implementation: library(ggplot2)ĭf = ame(x = rnorm(100), x2 = rnorm(100, mean=2)) (NB: that is the way I tend to compare distributions, especially more than 2. Many times people want to compare two distributions.Ĭookbook for R ) shows how to overlay histograms (or densities) on top of each other, so go there if that's what you want. Voilin plots are good for displaying data, but the violin must have the left and right (or top and bottom) of the violin to be from the same distribution, and therefore are symmetrical. I feel as though there should be a function like voilin plot from the vioplot package. A colleage of mine asked me how to do back to back histograms (instead of on top of each other).
