Skip to content
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

theme_set() breaks theme_void() if axis.text.x or axis.text.y is modified #2058

Closed
crsh opened this issue Feb 25, 2017 · 6 comments
Closed
Labels
bug an unexpected problem or unintended behavior themes 💃

Comments

@crsh
Copy link

crsh commented Feb 25, 2017

Hi, I'm having trouble with one of my custom themes since a recent update (I have tried with version 2.2.1 and the current snapshot from this repository). When I change the settings of axis.text.x or
axis.text.y in a theme that is set as default using theme_set(), theme_void() throws an error. This causes trouble when I try to use cowplot::plot_grid() (see my previous bug report).

library("ggplot2")

df <- data.frame(
    gp = factor(rep(letters[1:3], each = 10))
    , y = rnorm(30)
)
theme_set(theme_classic() + theme(axis.text.x = element_text()))

test <- ggplot(df, aes(gp, y)) + geom_point()

test # works
test + theme_void() # doesn't work
Error in element_grob.element_text(el, ...) : 
  Text element requires non-NULL value for 'angle'.

If I set angle and debug in element_text() it works.

test + theme_void() + theme(axis.text.x = element_text(angle = 0, debug = FALSE)) # works

Is this intended behavior?

@thomasp85
Copy link
Member

I don't really think this is a bug - you need to specify the angle the text should be written in. Usually this is derived from the root text element but since this is element_blank in theme_void() you'll need to specify it when you modify child elements...

@crsh
Copy link
Author

crsh commented Feb 28, 2017

What is very surprising to me is that I don't make any changes to theme_void(). I modify theme_classic() and set that modified version as default. Still this causes problems with theme_void(). I came across this behavior working with a custom theme of my own where I modify axis text margins. I don't make any changes to the angle and I don't touch theme_void().

Moreover, if I nevertheless set angle to any value, I get the following error

Error in if (debug) { : Argument has length 0

which is why in my continued example I also set debug = FALSE.

Also, I played a little more with this and when I make changes to, e.g., axis.title.x I get the same angle-error, but when I do set angle explicitly I get a new error:

theme_set(theme_classic() + theme(axis.title.x = element_text(angle = 0)))

test <- ggplot(df, aes(gp, y)) + geom_point()

test # works
test + theme_void() # doesn't work
Error in unit(rep(xp, n), "npc") : 'x' and 'units' must have length > 0

@has2k1
Copy link
Contributor

has2k1 commented Feb 28, 2017

I think it is a bug. theme_void() is a complete theme so whatever the default theme (the one set with theme_set) is should not affect it.

@thomasp85
Copy link
Member

Yeah, I can see that now. I'll look into it

has2k1 added a commit to has2k1/ggplot2 that referenced this issue Mar 20, 2017
**Issue**
At plot time, the calculation of theme elements always fell back
to the default theme. As a consequence, the default theme would
leak into complete themes where some of the elements were
unspecified.

**Solution**
Be more specific when calculating the theme defaults.

**Clean Up**
`theme_void` was insufficiently specified. The solution exposed
missing elements that had to be specified.

Fixes tidyverse#2058
Fixes tidyverse#2079
@karawoo karawoo added bug an unexpected problem or unintended behavior themes 💃 labels Jun 12, 2017
has2k1 added a commit to has2k1/ggplot2 that referenced this issue Jul 3, 2017
**Issue**
At plot time, the calculation of theme elements always fell back
to the default theme. As a consequence, the default theme would
leak into complete themes where some of the elements were
unspecified.

**Solution**
Be more specific when calculating the theme defaults.

**Clean Up**
`theme_void` was insufficiently specified. The solution exposed
missing elements that had to be specified.

Fixes tidyverse#2058
Fixes tidyverse#2079
has2k1 added a commit to has2k1/ggplot2 that referenced this issue Jul 14, 2017
**Issue**
At plot time, the calculation of theme elements always fell back
to the default theme. As a consequence, the default theme would
leak into complete themes where some of the elements were
unspecified.

**Solution**
Be more specific when calculating the theme defaults.

**Clean Up**
`theme_void` was insufficiently specified. The solution exposed
missing elements that had to be specified.

Fixes tidyverse#2058
Fixes tidyverse#2079
has2k1 added a commit to has2k1/ggplot2 that referenced this issue Aug 1, 2017
**Issue**
At plot time, the calculation of theme elements always fell back
to the default theme. As a consequence, the default theme would
leak into complete themes where some of the elements were
unspecified.

**Solution**
Be more specific when calculating the theme defaults.

**Clean Up**
`theme_void` was insufficiently specified. The solution exposed
missing elements that had to be specified.

Fixes tidyverse#2058
Fixes tidyverse#2079
@gilliganondata
Copy link

gilliganondata commented Sep 15, 2017

I've run into this a couple of times and wind up back on this issue each time. The thing I keep forgetting is that this does not cause an issue if simply axis.title() is set. It only seems to come into play (for me) when I'm trying to set axis.title.x() or axis.title.y() explicitly. With that in mind, I've been able to find various workarounds.

@hadley hadley closed this as completed in 6770641 Nov 1, 2017
@crsh
Copy link
Author

crsh commented Nov 13, 2017

Hooray for the fix. Thanks!

@lock lock bot locked as resolved and limited conversation to collaborators Jun 18, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug an unexpected problem or unintended behavior themes 💃
Projects
None yet
Development

No branches or pull requests

5 participants