Closed rdboyes closed 2 months ago
You can't have periods in Julia argument names so may need to be inherit_aes
.
One way this can be achieved is to add another field to Geom
called kwargs
and it basically acts as a sink for all other keywords passed into the geom. A basic example looks like this
struct Geom{K}
f1::Type1
f2::Type2
....
kwargs::K
end
Then in the geom_function
of geom_template
, pass kwargs
on to the build_geom
function:
return build_geom(aes_dict, args_dict,
required_aes,
spec_api_function,
aes_function,
merge(transforms, column_transformations),
kwargs)
Finally you can define a method that checks if kwargs
has the inherit_aes
keyword
inherit_aes(geom::Geom) = get(geom.kwargs, :inherit_aes, true)
This let's you keep the default inherit_aes=true
while letting users pass in the option to turn it off. Additionally this sets you up to support other keywords in the future.
If you don't want to add a type constraint on kwargs
, then you can convert it to a Dict{Symbol, Any} and have that as a concrete type in the struct
Thanks @adknudson - I implemented a modified version of your suggestion, since geoms were already automatically absorbing any extra kwargs into their args_dict
. In dev:
ggplot(penguins, aes(x = :bill_length_mm, y = :bill_depth_mm)) +
geom_point() +
geom_hline(yintercept = 18, inherit_aes = false)
Describe how it works in R's
ggplot2
inherit.aes
istrue
by default, and when set tofalse
, it prevents the geom from inheriting the plot default aes.Describe any changes you think should be made to R's version None