You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Cannot set legend.box.background with theme_void() #2723
df<-data.frame(x=1:3)
ggplot(df, aes(x, x, color=factor(x))) +
geom_point() +
theme_void() +
theme(legend.box.background= element_rect(fill="gray80"))
#> Warning in if (theme$legend.box == "horizontal") {: the condition has#> length > 1 and only the first element will be used#> Warning in if (theme$legend.box == "vertical") {: the condition has length#> > 1 and only the first element will be used#> Error in gtable_add_cols(guides, theme$legend.box.margin[4], pos = 0): is.gtable(x) is not TRUE
theme$legend.box is NULL but theme$legend.box.background is not, and thus theme$legend.box %||% "vertical" is partially matching on theme$legend.box.background and inserting the element_rect() into theme$legend.box.
@karawoo Can you think of a clean and simple fix at line 102?
In any case, I think it's always a good idea to have a default option in an if--else chain, so I would change line 266 regardless. And theme_void() needs to define legend.box.
Activity
clauswilke commentedon Jun 28, 2018
Also, this works without
theme_void(), of course:Created on 2018-06-28 by the reprex package (v0.2.0).
ptoche commentedon Jun 28, 2018
works for me:
sessionInfo()
R version 3.5.0 (2018-04-23)
Platform: x86_64-apple-darwin15.6.0 (64-bit)
Running under: macOS High Sierra 10.13.4
Matrix products: default
BLAS: /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/3.5/Resources/lib/libRlapack.dylib
locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
attached base packages:
[1] stats graphics grDevices utils
[5] datasets methods base
other attached packages:
[1] ggplot2_2.2.1
loaded via a namespace (and not attached):
[1] labeling_0.3 colorspace_1.3-2
[3] scales_0.5.0 compiler_3.5.0
[5] lazyeval_0.2.1 plyr_1.8.4
[7] tools_3.5.0 pillar_1.2.3
[9] gtable_0.2.0 tibble_1.4.2
[11] yaml_2.1.19 Rcpp_0.12.17
[13] grid_3.5.0 digest_0.6.15
[15] rlang_0.2.1 munsell_0.5.0
batpigandme commentedon Jun 28, 2018
I'm able to reproduce this with the latest dev. build.
Traceback
clauswilke commentedon Jun 28, 2018
It's probably related to the changes in the theme inheritance code in the latest version. Some edge case that wasn't considered.
clauswilke commentedon Jun 28, 2018
I've figured it out. The immediate cause is a missing
legend.boxelement in the theme:Created on 2018-06-28 by the reprex package (v0.2.0).
The ulterior reason is this
if--elsesequence:ggplot2/R/guides-.r
Lines 251 to 280 in 348b26f
It contains no default if
legend.boxis neither "horizontal" nor "vertical". I think this line:ggplot2/R/guides-.r
Line 266 in 348b26f
should be turned into an unconditional
else.karawoo commentedon Jun 28, 2018
I think the fix should actually occur earlier in this section of
build_guides():ggplot2/R/guides-.r
Lines 102 to 114 in 348b26f
theme$legend.boxisNULLbuttheme$legend.box.backgroundis not, and thustheme$legend.box %||% "vertical"is partially matching ontheme$legend.box.backgroundand inserting theelement_rect()intotheme$legend.box.clauswilke commentedon Jun 29, 2018
@karawoo Can you think of a clean and simple fix at line 102?
In any case, I think it's always a good idea to have a default option in an if--else chain, so I would change line 266 regardless. And
theme_void()needs to definelegend.box.karawoo commentedon Jun 29, 2018
The easiest I guess would be to change
theme$legend.box %||% "vertical"totheme[["legend.box"]] %||% "vertical". Agreed on the other points though.Provide default option in if--else chain. Closes tidyverse#2723.
clauswilke commentedon Jun 29, 2018
@karawoo I'm moving that discussion to separate issue #2724.
lock commentedon Jan 5, 2019
This old issue has been automatically locked. If you believe you have found a related problem, please file a new issue (with reprex) and link to this issue. https://reprex.tidyverse.org/
Make legend.box.background work for theme_void() (tidyverse#2725)