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
I had always assumed that the following were equivalent. They are not. Is it a feature of theming that all the options must be set in theme() in one pass?
Perhaps the same issue: To display the axis line, I need to set axis.ticks.length. Change unit(1, "cm") to unit(0, "cm") or drop that last line altogether and the axis line disappears.
This is a bug with theme_void(). It declares itself to be a complete theme but misses elements. This keeps coming up in various ways and the correct way to fix it is to define all theme elements in theme_void(). See e.g. #2723.
Actually, while theme_void() is still missing theme elements that it should define, maybe the right place to point the finger to here is this issue: #2724
Third time is a charm. I think I've found the real culprit: theme_void() sets line = element_blank(), and that means if downstream elements try to inherit from line they don't get reasonable defaults. It's actually surprising that the first example works, and I'm still not sure why. In any case, if line is defined appropriately things work as one would expect:
This still means theme_void() needs to be rethought. I think it should define a standard line element and then set the downstream elements (axis.line(), axis.ticks(), etc.) to element_blank().
The fundamental problem here is that adding themes to the plot object doesn't behave the same as adding themes to each other and seems buggy. Specifically, adding additional theme elements seems to convert parts of an incomplete theme into parts of a complete theme in the plot building process.
# Update the theme elements with the things from newtheme
# Turn the 'theme' list into a proper theme object first, and preserve
# the 'complete' attribute. It's possible that oldtheme is an empty
# list, and in that case, set complete to FALSE.
old.validate<- isTRUE(attr(oldtheme, "validate"))
new.validate<- isTRUE(attr(newtheme, "validate"))
oldtheme<- do.call(theme, c(oldtheme,
complete= isTRUE(attr(oldtheme, "complete")),
validate=old.validate&new.validate))
oldtheme+newtheme
}
I think the right logic would be to first add all the theme parts together with add_theme() during plot construction, and only fill in the missing pieces once the plot is built. This fits logically with the changes discussed in PR #2784.
I think we agree this is a bug. How can I add a "bug" label to this issue? Do I need special rights or have I missed the icon on which to click? Currently it says "Labels: 'None yet'". Thanks.
Activity
ptoche commentedon Dec 15, 2018
Perhaps the same issue: To display the axis line, I need to set
axis.ticks.length. Changeunit(1, "cm")tounit(0, "cm")or drop that last line altogether and the axis line disappears.clauswilke commentedon Dec 15, 2018
This is a bug with
theme_void(). It declares itself to be a complete theme but misses elements. This keeps coming up in various ways and the correct way to fix it is to define all theme elements intheme_void(). See e.g. #2723.Created on 2018-12-15 by the reprex package (v0.2.1)
clauswilke commentedon Dec 15, 2018
Actually, while
theme_void()is still missing theme elements that it should define, maybe the right place to point the finger to here is this issue: #2724In any case, it's a bug.
clauswilke commentedon Dec 15, 2018
Third time is a charm. I think I've found the real culprit:
theme_void()setsline = element_blank(), and that means if downstream elements try to inherit fromlinethey don't get reasonable defaults. It's actually surprising that the first example works, and I'm still not sure why. In any case, iflineis defined appropriately things work as one would expect:Created on 2018-12-15 by the reprex package (v0.2.1)
This still means
theme_void()needs to be rethought. I think it should define a standard line element and then set the downstream elements (axis.line(),axis.ticks(), etc.) toelement_blank().ptoche commentedon Dec 15, 2018
Thanks for the feedback and sleuthing Claus!
I suspect
theme_minimal()is also incomplete? Same apparent problem as withtheme_void().No problem that I can see with
theme_bw(),theme_gray(),theme_classic().Not sure about
theme_light()andtheme_dark(), which I don't use. This is the output:Created on 2018-12-16 by the reprex package (v0.2.1)
clauswilke commentedon Dec 15, 2018
There seem to be multiple issues at play here. There clearly is a difference between
theme(x, y)andtheme(x) + theme(y), and there shouldn't be.Created on 2018-12-15 by the reprex package (v0.2.1)
clauswilke commentedon Dec 15, 2018
The fundamental problem here is that adding themes to the plot object doesn't behave the same as adding themes to each other and seems buggy. Specifically, adding additional theme elements seems to convert parts of an incomplete theme into parts of a complete theme in the plot building process.
Created on 2018-12-15 by the reprex package (v0.2.1)
clauswilke commentedon Dec 15, 2018
I've tracked it down. When themes are added to the plot the function that is used is
update_theme():ggplot2/R/plot-construction.r
Lines 103 to 105 in 9292832
But when two themes are added together directly, the function is
add_theme():ggplot2/R/plot-construction.r
Line 51 in 868fdb7
The two functions have different logic, because
update_theme()pulls in information from the default theme if otherwise missing:ggplot2/R/theme.r
Lines 470 to 493 in 442108d
I think the right logic would be to first add all the theme parts together with
add_theme()during plot construction, and only fill in the missing pieces once the plot is built. This fits logically with the changes discussed in PR #2784.ptoche commentedon Jan 11, 2019
I think we agree this is a bug. How can I add a "bug" label to this issue? Do I need special rights or have I missed the icon on which to click? Currently it says "Labels: 'None yet'". Thanks.
clean up and simplify theme addition. fixes tidyverse#3039
lock commentedon Apr 25, 2020
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/
Clean up theme addition (tidyverse#3570)