Skip to content

In stat_density(), the calculated count aesthetic should take weights into account #4176

Closed
@tuberculo

Description

@tuberculo

The weight should sum to one, ignoring color or fill aesthetics. That was the behavior before as can be seen here: https://stackoverflow.com/questions/20342494/density-of-each-group-of-weighted-geom-density-sum-to-one
In the way that geom_density is now there is no way to make the sum of both areas be equal to one.

Example:

library(ggplot2)
library(ggplot2movies) 
m <- ggplot()
m + geom_density(data = movies, aes(rating, weight = votes, colour = factor(Action)))

The plot above is equal to

m + geom_density(data = movies[movies$Action == 0, ], aes(rating, weight = votes/sum(votes)), fill=NA, colour="black") +
    geom_density(data = movies[movies$Action == 1, ], aes(rating, weight = votes/sum(votes)), fill=NA, colour="blue")

I would expect a much smaller area for Action == 1 in the first plot, as less than 10% of the movies are action movies.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions