Hi folks!
I have been struggling with a problem on how to best plot variables that are not always guaranteed in data. Let me show an example of what I am talking about:
Suppose I have a dataframe that looks something like this:
10×4 DataFrame
Row │ age_group gender_concept_id race_concept_id count
│ String? Int32? Int32? Int64
─────┼──────────────────────────────────────────────────────
1 │ 50 - 59 8532 8527 403
2 │ 40 - 49 8532 8515 51
3 │ 30 - 39 8507 8516 20
4 │ 50 - 59 8507 8527 445
5 │ 40 - 49 8532 8516 59
6 │ missing 8532 8527 139
7 │ 60 - 69 8532 8516 43
8 │ 50 - 59 8532 8516 69
9 │ 80 - 89 8532 8527 102
10 │ 30 - 39 8507 8527 114
Then, I have a bespoke plotting function that will generate a plot that looks something like this which contains multiple subplots:
Then, suppose that I receive a similar dataframe that only has age group and count. I’d then want to subset the data like this with my function and generate one plot:
I have been exploring around how one might create a function mechanism using the idea of faceting that allows one to input a dataframe to a function built around something like AlgebraOfGraphics that seems to enable one the ability to loosely do this automatic plotting approach. But I am still not sure; I do realize that this problem is asking for a solution that does a bit of mind-reading but it feels like some aspects of it should be able to be automated.
Does anyone have any ideas on how to approach this and if AlgebraOfGraphics might be a good place to start looking? Happy to provide more details as it is a bit of a vague problem description.
Cheers!
~ tcp