-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Convert guide system to ggproto #3329
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
Comments
The ggplot2 book softly discourages extending ggplot's guide system. However, I'm pretty keen on making some guide extensions, so I'd be willing to spend some time experimenting. What are the current thoughts on moving the guide system to ggproto? I've heard on the grapevines that the entire secondary axis mechanism might move to guides, for example. Other than simply wrapping guide code into ggproto methods and making appropriate classes, what would need to change? |
@teunbrand I can expand a bit on why I've yet to build up the stamina to do this. If it were a simple rewrite of the current guide methods into a ggproto system it would be quite quick and we would have done it years ago. However, I want this to be an opportunity to rethink the guide implementation in a better way. Currently there is so much code duplication between the different legend guides in terms of how to lay out the grobs, calculate ticks etc. One could even go so far as to say that the keys in a colorbar guide is actually an instance of an axis guide and should use that implementation - but can that be generalised to e.g. the legend guide? There are quite a number of questions about how to do this properly in a manner that doesn't constraint future guide development but allows maximum code reuse. This is not to deter you from taking on the task. I would be happy if you had the stamina for it, and I would love to set off some time to discuss and guide you through it so you end up with a PR that we agree with the direction on. |
Thanks for your thoughts Thomas, they make a lot of sense to me. From an extension POV, it would be useful too if (in particular the drawing) code was more modular in some ways, which would align with the perspective of reducing code duplication if these modules can be re-used in different guides. For example, if you'd like to make ticks for the minor breaks, you wouldn't want to touch the axis lines or labels parts. I'll have a walk through the code at some point and take stock of what is the same/very similar or very different between various guides. |
yes, exactly. If we are going to do it we are going to do it with thought and intent. If you want to take it on I will be happy to have one or more design meetings to discuss your ideas and give you feedback |
I'd be willing to take a stab at this, but it may take quite some time before we find appropriate solutions. Worst case scenario is we can't figure out an elegant solution, and we're back where we started with some lessons learned along the way. I'd definitely be happy to get some guidance along the way, I don't consider this a small task. Below, I've made some notes going through the guide code trying to understand what some guides share and what is specific to a guide. I think that the shared bits might be modularised in some way. NotesGeneral ideas
General notes
Training tasksCommon tasks
Specific tasks
Merging tasksCommon tasks
Specific tasks
Transform tasksCommon tasks
Specific tasks
|
I do want to spend some time trying to get this to work. How about I just make a |
That may be a good idea to get the ball rolling |
The guide system, as the last remaining chunk of ggplot2, has been rewritten in ggproto. The axes and legends now inherit from a <Guide> class, which makes them extensible in the same manner as geoms, stats, facets and coords (#3329, @teunbrand). In addition, the following changes were made: * Styling theme parts of the guide now inherit from the plot's theme (#2728). * Styling non-theme parts of the guides accept <element> objects, so that the following is possible: `guide_colourbar(frame = element_rect(...))`. * Primary axis titles are now placed at the primary guide, so that `guides(x = guide_axis(position = "top"))` will display the title at the top by default (#4650). * Unknown secondary axis guide positions are now inferred as the opposite of the primary axis guide when the latter has a known `position` (#4650). * `guide_colourbar()`, `guide_coloursteps()` and `guide_bins()` gain a `ticks.length` argument. * In `guide_bins()`, the title no longer arbitrarily becomes offset from the guide when it has long labels. * The `order` argument of guides now strictly needs to be a length-1 integer (#4958). * More informative error for mismatched `direction`/`theme(legend.direction = ...)` arguments (#4364, #4930). * `guide_coloursteps()` and `guide_bins()` sort breaks (#5152).
The guide system is the last remaining major ggplot2 component that has not been converted to ggproto. As a consequence, it doesn't match well with the rest of the ggplot2 code base, and it is difficult to extend by external package maintainers. We should consider converting it over, possibly before building additional components that would use the current system, as in #3322.
The text was updated successfully, but these errors were encountered: