haleyjeppson/ggmosaic

factor level with 0 counts does not show up correctly

Closed this issue · 4 comments

There is no child crew members, but those tiles incorrectly shows up due to spill over of 3rd Class & child

> data(Titanic)
> a <- as.data.frame(Titanic)
> ggplot(data = a) + geom_mosaic(aes(x = product(Class), fill=Survived, weight=Freq)) + facet_grid(Age~Sex)
> 

screen shot 2019-02-13 at 5 10 31 pm

I have the same issue :(
It's ok when I set the offset to zero...

EDITED: Quick fix in my fork, in the divider file (last two commits)
Does the job on my case, haven't tested everything...
Plus I still feel we "see" a fine line of colors for theses 0 weight lines... removing offsets might not be the way to go...

heike commented

This is not a bug, it is a feature. The fine line is an indicator to which of the cell combinations is zero. Otherwise there is visually no way to distinguish between zero kids in the crew and any of the other factors.

I would agree if the initial data.frame has zeros in it, but since at some point the code is expanding all case it add zeros which were not present.
Maybe it could be added as an option somewhere?

heike commented

It is tricky to talk about the 'initial data.frame' in the context of a mosaic plot. Mosaic plots are a rendering of a contingency tables. Those do have zeroes, and it is informative to know where these zeroes are.
As an option to not show the space, you can always go to offset = 0.
Anything else will affect the validity of the representation.