Closed pank closed 3 years ago
Hi there,
I had this issue myself too (question on stack overflow) and this also happens in facet_grid()
, on which facet_nested()
is based. The ggplot2 maintainer Thomas is aware of this strip size issue, but it seems that it has been postponed until later. I don't think it makes much sense for me to work on this, if ggplot2 already plans to work on this (and thus facet_nested()
will inherit from facet_grid()
).
In any case, I don't think setting relative widths would be the solution to this problem. If I get around to #40 you would be able to set different margins for the text in different levels, which feels like a more natural integration than setting relative sizes.
Best, Teun
Hi,
Interesting. You are right, this is definitely an upstream issue. I must admit, I forgot to check vanilla ggplot2 as nested facets aren't so useful there.
Thanks for the informative links.
I might see if there's scope for opening an upstream issue.
Thanks!
26 Apr 2021 19.01.18 Teun van den Brand @.***>:
Hi there,
I had this issue myself too (question on stack overflow[https://stackoverflow.com/questions/62595394/crop-strip-background-when-combining-long-and-short-facet-labels]) and this also happens in facet_grid(), on which facet_nested() is based. The ggplot2 maintainer Thomas is aware[https://github.com/tidyverse/ggplot2/pull/3683#issue-355673008] of this strip size issue, but it seems that it has been postponed until later. I don't think it makes much sense for me to work on this, if ggplot2 already plans to work on this (and thus facet_nested() will inherit from facet_grid()).
In any case, I don't think setting relative widths would be the solution to this problem. If I get around to
40[https://github.com/teunbrand/ggh4x/issues/40] you would be able to
set different margins for the text in different levels, which feels like a more natural integration than setting relative sizes.
Best, Teun
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub[https://github.com/teunbrand/ggh4x/issues/41#issuecomment-826999341], or unsubscribe[https://github.com/notifications/unsubscribe-auth/AAFCZXM3ZULB3MHJYPE7AGTTKWL5NANCNFSM43TGNFIQ].
[data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEgAAABICAYAAABV7bNHAAAABHNCSVQICAgIfAhkiAAAACtJREFUeJztwQENAAAAwqD3T20ON6AAAAAAAAAAAAAAAAAAAAAAAAAAAD4MUUgAARy2AfAAAAAASUVORK5CYII=###24x24:true###][Tracking image][https://github.com/notifications/beacon/AAFCZXNHKCVIRBWDZBU53DTTKWL5NA5CNFSM43TGNFI2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOGFFQELI.gif]
I'm going to reopen this, because I've changed my mind on the feasability. I've read up some source code and I've become persuaded that this is doable.
The following should now work with the github version:
library(ggplot2)
library(ggh4x)
df <- data.frame(outer = c("A","B", "B", "C", "C", "C"),
inner = paste("Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua", 1:6),
x=1, y =1)
theme_set(theme_gray() + theme(strip.text.y.left = element_text(angle = 0)))
ggplot(df, aes(x,y)) +
geom_point() +
facet_nested(outer + inner ~ .,
scales = "free_y",
switch = "y",
space = "free_y",
labeller = label_wrap_gen(40),
strip = strip_nested(size = "variable")
) +
scale_y_discrete(label = NULL)
Created on 2021-06-29 by the reprex package (v1.0.0)
Please be aware that this still may contain some bugs (see #45), and let me know if you find some more :)
Currently, nested facets seem to get exactly the same width (for the y-axis) for the outer and the inner facet. But either the inner or the outer facet might have more text.
It would be useful to be able to specify the relative width that the inner and outer facet label each get. For instance in the example below, it would have maybe been nice to specify that the outer facet takes 1/3 of the horizontal space and the inner takes 2/3 of the horizontal space.
I have not been able to figure out how to do this with
grid
(but I am also not proficient with it).It seems both facets are in the same grid column, but I can't figure out how to set relative levels.
In any case, it would be nicer to be able to specify this at the ggplot2-level
Many thanks,
Example: