ggalt icon indicating copy to clipboard operation
ggalt copied to clipboard

Proposal of a stat_prop()

Open larmarange opened this issue 4 years ago • 0 comments

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

larmarange avatar Feb 02 '20 17:02 larmarange