ggmosaic
ggmosaic copied to clipboard
Request for easy way to label tiles
Mosaic plots are great way to inform about proportions within groups, but they give you now way to indicate the total sample size / subgroup sizes. It's impossible to use geom_mosaic with geom_text to label tiles. Would it be possible to create an easy way to add geom_text to plots with geom_mosaic? That could result in:
- labeling tiles (like here)
- presenting raw numbers behind plots (which is crucial in case you are visualizing populations of different sizes).
I second the motion! It would be extremely helpful to be able to label the tiles in an easy way.
I believe geom_mosaic_labeldoes that.
Quick hack if you want to display the count of cases:
ggplot(data = titanic) +
ggmosaic::geom_mosaic(aes(x = ggmosaic::product(Class), fill = Survived)) +
ggmosaic::geom_mosaic_label(aes(x = ggmosaic::product(Class), fill = Survived, label = after_stat(.wt))) +
ggmosaic::scale_x_productlist()
I believe
geom_mosaic_labeldoes that.Quick hack if you want to display the count of cases:
ggplot(data = titanic) + ggmosaic::geom_mosaic(aes(x = ggmosaic::product(Class), fill = Survived)) + ggmosaic::geom_mosaic_label(aes(x = ggmosaic::product(Class), fill = Survived, label = after_stat(.wt))) + ggmosaic::scale_x_productlist()
This reply is very helpful. I kept searching for a long time until I found this.
For new readers, just note that the function name now is ggmosaic::geom_mosaic_text()