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

Proposal of a stat_prop() #66

Open larmarange opened 4 years ago

larmarange commented 4 years ago

I have developed a new stat for ggplot2 allowing to compute proportions according to a specified denominator.

For example, it allows to compute and to display column proportion on a bar chart with position = fill.

ggplot(as.data.frame(Titanic)) +
  aes(x = Class, fill = Survived, weight = Freq) +
  geom_bar(position = "fill") + 
  geom_text(aes(by = Class), stat = "prop", position = position_fill(.5))

will produce

image

Current code is visible here: https://github.com/larmarange/JLutils/blob/master/R/stat_prop.R

Do you think that such stat could be a good addition for ggalt? Or is it out of the scope of your package?

Best regards