Skip to content

stat_density() ignores weight #2902

Closed
@eliocamp

Description

@eliocamp

While both geom_density() and stat_density() compute weighted densities correctly, the later results in an spurious warning (the first of the bunch).

library(ggplot2)

df <- data.frame(x = runif(100))

ggplot(df, aes(x)) +
   stat_density(aes(weight = abs(x - 0.5))) +
   geom_density(aes(weight = abs(x - 0.5)), color = "red")
#> Warning: Ignoring unknown aesthetics: weight
#> Warning in density.default(x, weights = w, bw = bw, adjust = adjust, kernel
#> = kernel, : sum(weights) != 1 -- will not get true density

#> Warning in density.default(x, weights = w, bw = bw, adjust = adjust, kernel
#> = kernel, : sum(weights) != 1 -- will not get true density

Created on 2018-09-19 by the reprex package (v0.2.0).

(I'm sorry if the multiple similar issues are not cool; you can tell that I'm working with weighted densities in my work and finding these small issues 😆 )

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugan unexpected problem or unintended behaviorlayers 📈tidy-dev-day 🤓Tidyverse Developer Day

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions