EvaMaeRey / statexpress

stat express
0 stars 0 forks source link

new direction qstat and qlayer #5

Open EvaMaeRey opened 2 weeks ago

EvaMaeRey commented 2 weeks ago

Work stopped for a while on this project because of the following approach which seemed really concise and in-script appropriate:

StatNew <- ggproto("StatNew", Stat, compute_group = my_compute()

p + geom_polygon(stat = StatNew)

and wrapping up for more user facing...

geom_new <- function(...){ geom_polygon(StatNew, ...) }

And, the way I was headed seemed hard to keep track of and reason about.

But recent geom_manual work (in ggplot2 https://github.com/tidyverse/ggplot2/pull/6103) has me taking another look at that level of concision, but by piggybacking on the geom_polygon(stat = StatNew ) approach.

Basically, statexpress would provide two things. 1. qstat and 2. qlayer (which are pretty concise themselves actually).

qstat <- function(compute_group, ...){ggproto("StatTemp", Stat, compute_group = compute_group, ...) }

qlayer is just a cross between geom_point and stat_identity, but making both the geom and stat available, and will look a lot like the default boilerplate that you might copy and paste from your last user-facing layer function!

So you can do

p + geom_polygon(stat = qstat(my_compute))

So you don't need a step just dedicated to naming a stat.

But you have access to default aes, dropped aes, required aes, etc, and compute_panel...

qlayer is nice for cases when you need to use a geom that doesn't have a convenient user-acess way to change the stat:

p + qlayer(geom = GeomVline, stat = qstat(my_compute)

or also modified Geoms...

p + qlayer(geom = GeomNewPoint, Stat = qstat(my_compute))

EvaMaeRey commented 2 weeks ago

function formulation and how to use ideas: https://evamaerey.github.io/mytidytuesday/2024-09-20-corr-w-qstat-qlayer/corr-w-qstat-qlayer.html