geom_density ignores "weight" argument
See original GitHub issueHi, I noticed that when running pn.ggplot(df, pn.aes(x="x, weight="w")) + pn.geom_density()
the density is ignored.
I am using plotnine version 0.6.0.
I validated the difference by running df.reindex(df.index.repeat(df["w"]))
and plotting this without the weight argument.
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
Weighted ggplot2 warning: Ignoring unknown aesthetics: weight
I try to plot a weighted density with ggplot2. The results seem to be fine, but I get the following warning: Warning: Ignoring...
Read more >weighted density plots - Google Groups
I have observations that are weighted (all weights are between 0 and 1). I would like to use these weights as in the...
Read more >Density plot — ggdensity • ggpubr - R Packages
Arguments ; a data frame · variable to be drawn. · one of "density" or "count". · logical value. Default is FALSE. Used...
Read more >density ridges, plotting geom_vline using specific values for ...
It appears that the geom_density_ridges() geom cannot take weights in the calculation of the densities. However, it is quite common that...
Read more >Package 'ggplot2'
geom_density created. A function will be called with a single argument, the plot data. The return value must be a data.frame, ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I do not think you can do that, because for a kernel density algorithm there are two ways to affect the contribution of any distinct value towards the final density.
For stability of the algorithms the weighting (multiplication) is normalised to the [0, 1] domain for any given density computation. That shuts out option 2 leaving you with option 1.
So maybe you can make it easier by creating a helper function using something like
to come up with integer replication factors.
I encountered this issue as well. Please see the example below:
Produces the following plot:
If we do:
or
we get the same plot. However, if we do:
We get:
Which is the expected result.
@has2k1 is there a way to produce the last plot above using
weight
or without repeating rows in a dataframe?