hrbrmstr / ggalt

:earth_americas: Extra Coordinate Systems, Geoms, Statistical Transformations & Scales for 'ggplot2'
https://cran.r-project.org/web/packages/ggalt/vignettes/ggalt_examples.html
Other
654 stars 99 forks source link

Add ndensity computed group stat to StatBkde2d #61

Open seasmith opened 5 years ago

seasmith commented 5 years ago

Gives stat_bkde2d() the same behavior as stat_density2d() -- normalizing the density to the max density per group when facetting. Similar to the nlevel computed stat.

Before (density)

library(ggplot2)
library(ggalt) # from seasmith/ggalt branch add-ndensity

ggplot(iris, aes(Sepal.Length, Petal.Length)) +
    stat_bkde2d(aes(fill = stat(density)), geom = "raster", contour = FALSE) +
    facet_wrap(vars(Species))

before-ndensity

After (ndensity)

ggplot(iris, aes(Sepal.Length, Petal.Length)) +
    stat_bkde2d(aes(fill = stat(ndensity)), geom = "raster", contour = FALSE) +
    facet_wrap(vars(Species))

with-ndensity

hrbrmstr commented 5 years ago

Very welcome addition! Can you also add yourself to the DESCRIPTION?