Skip to content

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

Closed

Description

@crsh

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?

Activity

  1. thomasp85 commented on Feb 28, 2017

    @thomasp85
    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...

  2. crsh commented on Feb 28, 2017

    @crsh
    Author

    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
    
  3. has2k1 commented on Feb 28, 2017

    @has2k1
    Contributor

    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.

  4. thomasp85 commented on Feb 28, 2017

    @thomasp85
    Member

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

  5. added a commit that references this issue on Mar 20, 2017
    977e051
  6. added
    bug
    on Jun 12, 2017
  7. added a commit that references this issue on Jul 3, 2017
    6dd2836
  8. added a commit that references this issue on Jul 14, 2017
    0c02a27
  9. added a commit that references this issue on Aug 1, 2017
    a4184d5
  10. gilliganondata commented on Sep 15, 2017

    @gilliganondata

    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.

  11. crsh commented on Nov 13, 2017

    @crsh
    Author

    Hooray for the fix. Thanks!

  12. locked as resolved and limited conversation to collaborators on Jun 18, 2018
  13. added a commit that references this issue on Apr 1, 2026
    6770641
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugthemes 💃

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions