Multiple histograms in a plot using ggplot2 ggplot…

rencontre montreal celibataire Multiple histograms in a plot using ggplot2.

duicentro citas en linea san miguel ggplot(test.melt, aes(x = value, fill = sample)) + geom_histogram(alpha = 0.3, position = 'identity', aes(y = ..density..)) + geom_density(alpha = 0.3, position = 'identity')

Be careful. The default value for the


parameter is different the histogram and density plot. So set the parameter explicitly.

Identity: overlap the two histograms.
stack: stack the two histograms on top of another.
For more options, check Position adjustments in

Default parameters of histogram and density.

geom_histogram(mapping = NULL, data = NULL, stat = "bin", position = "stack", ...)
stat_density(mapping = NULL, data = NULL, geom = "area", position = "stack", adjust = 1,
  kernel = "gaussian", trim = FALSE, na.rm = FALSE, ...)
geom_density(mapping = NULL, data = NULL, stat = "density", position = "identity",
  na.rm = FALSE, ...)

Leave a Reply

Your email address will not be published. Required fields are marked *