-
Notifications
You must be signed in to change notification settings - Fork 3
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
In-panel labs #4
Comments
I think I understand the visual result you're describing, but maybe not the process you're thinking about using. Do you mean you'd:
|
I'll admit I didn't think this through very much... sorry for the confused description. I saw your package and thought it might be a good place to implement a solution for a related problem of tagging facets. My common use-case is to remove strips and add tags to facets, Your package is targetting a somewhat different problem, but maybe there could be some overlap where the tag contains the same kind of information as the glued facets strips? Just a thought, feel free to close this issue.
|
No, that's okay! I was just looking around for alternate ways to solve the problem and saw that at least one other person has taken a similar approach as you (use a dummy I'd certainly prefer to find a solution that respects the semantic function of the facet labels, but if that's not possible then maybe this approach is the best way to make it happen 🙂 |
ggplot2 v3 also appears to have a new |
yeah, I was a bit involved the tags discussion; maybe I should have pushed the per-facet option at the time. I suggested a couple of times making things like facet strips customisable in their gtable positioning, so that you could place e.g. the facet strip at a custom position within panels etc. but I don't think it'll ever gain traction among ggplot2 developers. |
That seems like a shame given I see you can now choose whether strips go between the axis and the panel as well as choosing the side they sit on. I understand being opinionated about defaults, but if you're allowing customisability, I don't see a massive difference between that and allowing them inside the panel (except, perhaps, that the existing options still allocate space for the strips, rather than overlaying them). |
Maybe a ggplot2 extension could achieve this as well? |
So, I need to really sit down with this on the weekend a bit more, but I've been poking around the ggplot2 code and I'm wondering if creating modified facet classes is the way to do this. There's a lot going on, but as far as I can tell the On the plus side, this would mean that facet labels could still be themed in the existing way. On the downside, this is a massively overengineered solution and changes in the facetting system in future versions of ggplot2 could mess it up. |
Another downside: implementing it for |
Okay, I'm following the Extending ggplot2 vignette to try to sketch out how this would work subclassing |
I'm about 3/4 of the way on the 'make a new facet spec' approach: the strips end up inside their respective panels, but due to this problem (I think), the strips are centre-justified: library(stickylabeller)
ggplot(mtcars) +
geom_point(aes(x = mpg, y = gear)) +
facet_wrap_overlay(~ carb) +
theme(strip.background = element_rect(fill = '#ff000080')) This is what the two functions look like in weave_tables_col <- function(table, table2, col_shift, col_width, name, z = 1, clip = "off") {
panel_col <- panel_cols(table)$l
panel_row <- panel_rows(table)$t
for (i in rev(seq_along(panel_col))) {
col_ind <- panel_col[i] + col_shift
table <- gtable_add_cols(table, col_width[i], pos = col_ind)
if (!missing(table2)) {
table <- gtable_add_grob(table, table2[, i], t = panel_row, l = col_ind + 1, clip = clip, name = paste0(name, "-", seq_along(panel_row), "-", i), z = z)
}
}
table
}
weave_tables_row <- function(table, table2, row_shift, row_height, name, z = 1, clip = "off") {
panel_col <- panel_cols(table)$l
panel_row <- panel_rows(table)$t
for (i in rev(seq_along(panel_row))) {
row_ind <- panel_row[i] + row_shift
table <- gtable_add_rows(table, row_height[i], pos = row_ind)
if (!missing(table2)) {
table <- gtable_add_grob(table, table2[i, ], t = row_ind + 1, l = panel_col, clip = clip, name = paste0(name, "-", seq_along(panel_col), "-", i), z = z)
}
}
table
} Inside that loop, I'm essentially commenting out the |
Cool, thanks for working on this. IIRC for a gtable within a gtable, use the vp argument to justify. All this should be compatible with npc units so probably no need to worry about panel dimensions. |
Awesome 😁 I have the strip backgrounds going to the top (or bottom) successfully by moving the actual strip height from the parent The text is proving trickier, though, as the |
Okay, this isn't quite ready for prime-time, but it's getting there 😄 p = ggplot(mtcars) +
geom_point(aes(x = mpg, y = gear)) +
facet_wrap_overlay(~ carb, labeller = label_glue('({.l}) carb is {carb}')) +
theme_grey(base_size = 10) +
theme(
strip.background = element_rect(fill = alpha('black', 0.5)),
strip.text = element_text(colour = 'white', hjust = 0, vjust = 1.15)) +
labs(
title = 'Overlay facet titles in ggplot2 with stickylabeller!',
subtitle = 'The facet_wrap_overlay function prints labels over the panels') I got a bit frustrated with not being able to make things work with the text justification, so I ended up just doing the maths on its position. Maybe that can be fixed up in time 😁 But for now, it works with |
Just the other day I needed a helper function to polish some plots for a paper: I often have facetted plots without facet strips to save on space, and the editors require a label
(a)
,(b)
, etc. for each facet, which they see as a sub-figure.It'd be nice to use your glue framework with this alternative labelling technique (a dummy text layer placed with the panels).
The text was updated successfully, but these errors were encountered: