Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

geom_stratum_text convenience layer? #137

Open
EvaMaeRey opened this issue Dec 3, 2024 · 2 comments
Open

geom_stratum_text convenience layer? #137

EvaMaeRey opened this issue Dec 3, 2024 · 2 comments

Comments

@EvaMaeRey
Copy link

Just wondering about a convenience layer geom_stratum_text() instead of recommended:

geom_text(stat = "stratum", aes(label = after_stat(stratum)))

Then default_aes for StatStratum would be aes(label = after_stat(stratum)) and geom = GeomText

@corybrunson
Copy link
Owner

corybrunson commented Dec 4, 2024

Hi @EvaMaeRey ! This is something i would have resisted a few years ago, but i'm becoming more comfortable with the convenience of composite geoms nowadays.

I wonder if the following would make more sense: No additional stat_*() or geom_*() functions, but a new text parameter in geom_stratum() that, when TRUE, would trigger an additional text layer using the label aesthetic (with the default you suggest). The default of the text parameter would be FALSE, so as not to break legacy code. So, you could do in one line what would previously take two:

stat_stratum(text = TRUE)

Does that sound good? Or do you think a new geom_stratum_text() function would be appropriate? Even better, is there an example geom_*() out there that does something similar and does it well?

@EvaMaeRey
Copy link
Author

EvaMaeRey commented Dec 4, 2024

I think I'd favor geom_stratum_text(). Two packages that come to mind are ggcirclepack (geom_circlepack and geom_circlepack_test) and ggstats's diverging bar charts (geom_likert and geom_likert_text) for example. I like less of the action to happen in arguments and instead composition via + operator.

This is something i would have resisted a few years ago, but i'm becoming more comfortable with the convenience of composite geoms nowadays.

My current thinking is:

  1. stat_stratum() - define w/ Stat and GeomRect, and Geom rect is switchable, and user-facing function works as advertized
  2. geom_stratum() - allias of stat_stratum; even more user-facing. you could switch out the geom, but it might feel weird. Anticipate to use as-is.
    and friends
  3. geom_stratum_text()- Stat and Geom are fixed, (Stat has an appropriate default aes for case where label is required aes for Geom)
  4. geom_stratum_label()

Then you can write, which, I think, is quite user friendly.

ggplot(data) + 
 aes(...) + 
 ...
 ...
 geom_stratum() + 
 geom_stratum_text() 

(And you could even have an alias of the alias geom_stratum_rect() which spells out the stat and geom, but I feel kind of on the fence about it)

More folks' perspectives are here: teunbrand/ggplot-extension-club#36 and

I think this layer_* idea is especially worth noting, teunbrand/ggplot-extension-club#36 (reply in thread), but I think the convention is to use geom_* to mean layer and layer_* would really be going your own way and potentially confuse users. I push back in the thread! I hope you buy it! 😅 You should definitely weigh in if you've got some thoughts on this, which it sounds like you might! (i.e. fleshing out 'I would have resisted a few years ago...')

I think for circlepacking and stratum there might be a greater cause for labels to be more automatic (text = TRUE) where two layers are drawn as default , as it's kind of a legend for the geoms that you get for free when mapping to something like x or y (its pretty hard to interpret stratum and packed circles w/o labels whereas likert plots might be ok w/o - likert labels just give you greater precision about areas). But feels like having rect/cirlce and label layer in one function call feels tricky to me.

I got here from your JSM who-are-extenders discussion, btw. :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants