ProjectMOSAIC / ggformula

Provides a formula interface to 'ggplot2' graphics.
Other
39 stars 11 forks source link

Matching gf_percents() to tally() with a facet #130

Closed MichaelJMahometa closed 5 years ago

MichaelJMahometa commented 5 years ago

When running:

library(mosaic)
tally( ~ substance | sex , data = HELPrct, format="percent")

The resulting percentages are within the facet groups (sex)--matching the margins total to 1. When using the same formulation in gf_percents():

gf_percents( ~ substance | sex , data = HELPrct)

The resulting percentages in the graph are not matching the tally() output--they are not conditional percentages within the facet panel---they are full table percentages.

This seems incongruous with the desire of mosaic and ggformula working synonymously with the formula definitions.

If there is a way for gf_percents() to match the tally() with an option, I'll take it...as I'd like to use both---and hopefully have them match---this semester.

Thanks, Michael

rpruim commented 5 years ago

This is a feature/limitation of ggplot2, and I don't know of any easy way to get the behavior that I think you want unless you precalculate the counts or percentages you want and then create the plot. df_stats() makes this relatively easy -- but not as easy as you would like.

See #118 for more information.

MichaelJMahometa commented 5 years ago

Thanks for this (and the reference link (don't know why I didn't see it with the search)). Thanks also for this work with ggformula.