Feature request: make clipping configurable #2536
I frequently would like to be able to draw things that fall outside of the plot panel. This is currently not possible, as clipping is strictly enforced and not configurable. I think it would be nice if this could be switched on or off. First, as motivation, an example where it would be useful. Then my proposal of how it could be implemented.
Consider this plot:
The top-most text label is cut off because it extends beyond the plot area. To make it fit, I could extend the axis range, but that would extend the axis line as well. It looks more elegant to switch of clipping and have the text label extend outside of the plot area:
I would like to propose to address this by making clipping a feature of the coordinate system. For example, the above plot could be generated by something like this:
This feature requires very minimal changes to the coord code and the facet layouting code. I'll see if I can put together a pull request implementing this.
The text was updated successfully, but these errors were encountered:
Not sure how realistic it is to change drawing order without causing all sorts of headaches. My vote would be to not touch that issue at this time but provide the clipping function for advanced users who can make use of it. Below, I'll mention some issues about drawing order for single-panel plots and multi-panel plots. In all cases, it comes down to the fact that panels are completely assembled before they are integrated into the rest of the plot.
1. Single-panel plots
Currently, the axes and axis lines are drawn after the panel is drawn and hence sit on top of the panel. This has bugged me at times, e.g. when the axis line sits on top of a bar in a bar plot. However, I think it needs to be this way. If we drew axis lines before we draw the panel, then the axis lines would be partially obscured by panels with opaque background, and that would be even worse. The correct drawing order would be to draw panel background, then panel grill, then axis lines, and then the geoms, but that would require a complete rethinking of the plot rendering process.
We can see that this issue arises from the documentation of
In any case, in essentially all cases I can envision where I would want to switch clipping off, I wouldn't have an axis line overlap with the panel contents that sticks out of the panel area, so I think this is a minor issue.
2. Multi-panel plots.
Drawing order is a bigger problem for multi-panel plots, because panels that are drawn later will sit on top of panels that were drawn earlier. The only true fix would be to completely separate out the drawing order, and first draw all panel backgrounds, then all panel grills, then the first geom for all panels, then the second geom for all panels, and so on. At this time, I don't think this is worth the amount of work needed and the potential for breaking something. The alternative would be to simply continue to enforce clipping in faceted plots, but my attitude would be that it's always better to make things configurable than not.
However, if I'm missing something and there's an substantial improvement that can be had without rewriting all the rendering code then I'm happy to look into that.