Is there a simple method to exclude empty categories from charts
5 vues (au cours des 30 derniers jours)
I ran into this same problem with some of my charts. I take a subset of the data, but the chart shows empty collumns for those categories that are not in the subset.
Is there a simple way to remove those categories, that does not require knowing what categories are not included ahead of time?
If I want to drill down by some other category or variable that excludes some of the x-axis categories, I get empty columns.
(as an example only) This example narrows the data set by filtering for Measure below a certain value. E006 and E011 are empty.
I could remove those from the graph by duplicating my dataset then removing the empty categories from that new data set. Or create a new category in the existing dataset and remove. Both of those would be manual, and sound excessive, especially for my somewhat large dataset.
Any recommendations are appreciated.
dpb le 19 Jan 2023
It's a little extra code to write, but it should be able to be made generic -- follow the lead of @Cris LaPierre in that thread; wrap the categorical argument in your plotting routine inside removecats and use a logical addressing vector to address the elements left after your selection.
For the above example data;
results in the same figure as yours above as far as data but without the empty categories (and using plain vanilla scatter, of course).
If you're programmatically setting the limits or other selection criteria, it should be feasible to compute the required indexing variable(s) programmatically and avoid the manual intervention.