Density of each group of weighted geom_density sum to one
问题 How can I group a density plot and have the density of each group sum to one, when using weighted data? The ggplot2 help for geom_density() suggests a hack for using weighted data: dividing by the sum of the weights. But when grouped, this means that the combined density of the groups totals one. I would like the density of each group to total one. I have found two clumsy ways to do this. The first is to treat each group as a separate dataset: m <- ggplot() m + geom_density(data = movies