-
Notifications
You must be signed in to change notification settings - Fork 2.1k
strip.text.y = element_blank() yields an error when there are multiple layers of strip labels #4050
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
Thanks, confirmed. The error comes from here: Line 407 in 01df437
# Check that inputs have the right length
if (!all(vapply(
list(t, r, b, l, z, clip, name), len_same_or_1,
logical(1), n_grobs
))) {
stop("Not all inputs have either length 1 or same length same as 'grobs'")
} I have no idea what's happening here, sorry... |
I have an idea where this problem comes form. If the strips texts are rendered as blanks, you get strangely formatted grobs for the strips with incorrect lengths. library(ggplot2)
# Create full theme and theme with blank strip.text.y.right
theme_full <- theme_gray()
theme_blank <- theme_full + theme(strip.text.y.right = element_blank())
# Dummy labels
dummy <- data.frame(c("a", "b"), "b")
# Render strips
strip_full <- ggplot2:::render_strips(dummy, dummy, label_value, theme_full)
strip_blank <- ggplot2:::render_strips(dummy, dummy, label_value, theme_blank)
# The normal strips are a list of tablegrobs
strip_full$y$right
#> [[1]]
#> TableGrob (1 x 2) "strip": 2 grobs
#> z cells name grob
#> 1 1 (1-1,1-1) strip gTree[strip.gTree.83]
#> 2 2 (1-1,2-2) strip gTree[strip.gTree.87]
#>
#> [[2]]
#> TableGrob (1 x 2) "strip": 2 grobs
#> z cells name grob
#> 1 1 (1-1,1-1) strip gTree[strip.gTree.85]
#> 2 2 (1-1,2-2) strip gTree[strip.gTree.89]
# The 'blank' themed strips are a matrix of lists?
strip_blank$y$right
#> [,1] [,2]
#> [1,] List,3 List,3
#> [2,] List,3 List,3
# They have different lengths
length(strip_full$y$right)
#> [1] 2
length(strip_blank$y$right)
#> [1] 4 When you then naively try to add the blank strips to a gtable and not all arguments are length 1 you can get the error described. Below I use library(gtable)
gt <- gtable(unit(c(1, 1), "cm"), unit(c(1, 1), "cm"))
# Works fine
new_full <- gtable_add_grob(gt, strip_full$y$right, t = c(1, 2), l = 1)
# Returns the error
new_blank <- gtable_add_grob(gt, strip_blank$y$right, t= c(1, 2), l = 1)
#> Error in gtable_add_grob(gt, strip_blank$y$right, t = c(1, 2), l = 1): Not all inputs have either length 1 or same length same as 'grobs' Created on 2020-06-09 by the reprex package (v0.3.0) I hope this could help narrow the scope of the problem a bit. |
Thanks for your insight! |
Hello,
I was trying to remove the strip labels. I found that setting
strip.text.x = element_blank()
works when there is only one layer of strip labels and yields an error when there are multiple layers of labels. Is there any way to remove the strip labels in the latter case? Many thanks!The text was updated successfully, but these errors were encountered: