ggmosaic icon indicating copy to clipboard operation
ggmosaic copied to clipboard

Request for easy way to label tiles

Open kamilsi opened this issue 7 years ago • 4 comments

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:

  1. labeling tiles (like here)
  2. presenting raw numbers behind plots (which is crucial in case you are visualizing populations of different sizes).

kamilsi avatar Mar 27 '18 13:03 kamilsi

I second the motion! It would be extremely helpful to be able to label the tiles in an easy way.

neuwirthe avatar Oct 02 '18 16:10 neuwirthe

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() 

gregleleu avatar Dec 16 '20 02:12 gregleleu

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()

hnagaty avatar Jan 08 '22 11:01 hnagaty