-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Feature request: make the input panels of Facet$draw_panels()
predictable
#6406
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
On what part do you get stuck if you try to implement panel spanning dendrograms? I'm unsure the premise of #6396 (using communicating grobs) is the right way to go in this case. If we don't need communicating grobs, then the current situation with how |
Thanks, and apologies for the frequent PRs recently. I'm a big fan of circle plots and currently working on the circular design. The main issue I'm encountering relates to drawing order: ggplot2 renders each facet panel sequentially, meaning the entire drawing process for one panel is completed before the next begins. a segment drawn in one panel can be overridden by the background of the panel to its right: library(ggplot2)
ggplot(data.frame(x = c(1, NA), facet = c("a", "b"))) +
annotation_custom(
grob = grid::roundrectGrob(
gp = grid::gpar(fill = "red", col = "red"),
width = 0.5, height = 0.5
),
xmin = -Inf, xmax = Inf, ymin = -Inf, ymax = Inf
) +
geom_segment(aes(x, y = 1L), yend = 1, xend = 2L) +
facet_wrap(vars(facet), nrow = 1L) +
coord_cartesian(clip = FALSE) if the layer order is reversed, the segment overrides the annotation—even though the annotation was added after: ggplot(data.frame(x = c(NA, 1), facet = c("a", "b"))) +
geom_segment(aes(x, y = 1L), yend = 1, xend = 0) +
annotation_custom(
grob = grid::roundrectGrob(
gp = grid::gpar(fill = "red", col = "red"),
width = 0.5, height = 0.5
),
xmin = -Inf, xmax = Inf, ymin = -Inf, ymax = Inf
) +
facet_wrap(vars(facet), nrow = 1L) +
coord_cartesian(clip = FALSE) |
In the |
Thanks for the explanation. Isn't it possible to implement #6407 in the Facet class you're implementing to a degree that you don't get these overlap assymmetries? I also don't understand the desired behaviour here: do you want the annotation to be occluded by the neighbouring panel or not? |
I want the overall drawing order to follow the sequence in which layers are added. Specifically, this means starting with This approach ensures that what we input is exactly what we see. If the input |
If we were to put the following part under control of Lines 63 to 85 in 8b2a764
|
Yes, if that part were moved under the control of |
Hi, I'm planning to implement the feature of the ggalign package — the chord diagram — which will depend on this functionality. Would it be okay for me to open another PR to modify the relevant part of the code and add them to the Facet's |
I think it is better to create a new method for the Facet class than to cram it into the |
Thanks! Could you suggest a name for the method? Do you think |
I've named the method |
Related to #6398 and #6396.
After testing, I found it difficult to handle the original feature request using a single Facet object alone, since the
panels
input toFacet$draw_panels()
is unpredictable. It’s challenging to break down panels into individual layer grobs.Several issues contribute to this unpredictability:
Layer$draw_geom
method doesn't always return a grob if the developer doesn’t follow the expected conventions. No error or warning is issued in such cases, andgList(NULL)
orgList(gList())
simply works silently.Coord$draw_panel
will sometimes wrap all layer grobs into single gTree inCoordRadial
, sometimes it won'tSolutions:
Layer$draw_geom()
always returns a singlegrob
or agTree
.gTree
before passing toCoord$draw_panel
In this way, the input
panels
will always be a list ofgTree
object for each panel.each
gTree
object contains 3 children forCoord$render_fg
,Coord$render_bg
and anothergTree
ofFacet$draw_back
, all layer grobs, andFacet$draw_front
The text was updated successfully, but these errors were encountered: