Skip to content

theme() does no longer accept objects of class unit.arithmetic #1437

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

Closed
UweBlock opened this issue Dec 20, 2015 · 1 comment
Closed

theme() does no longer accept objects of class unit.arithmetic #1437

UweBlock opened this issue Dec 20, 2015 · 1 comment
Labels
bug an unexpected problem or unintended behavior
Milestone

Comments

@UweBlock
Copy link

Before ggplot v2.0.0 the following piece of code worked without problems

library(ggplot2)
x <- (1:8)
y <- sin(x)
z <- letters[1:2]
dat <- data.frame(x, y, z)
g <- ggplot(dat, aes(x, y, group = z, colour = z, fill = z)) + geom_area(alpha = 0.5)
t <- theme_bw() + theme(legend.position = "bottom")
g + t
# now with half height legend keys
t1 <- t + theme(legend.key.height = 0.5 * t$legend.key.size )
g + t1

Now, with ggplo2 v.2.0.0 I get the error message:

> Error in FUN(X[[i]], ...) : Unknown input

It seems that theme() does no longer accept objects of class unit.arithmetic.
WORKAROUND:

t2 <- t + theme(legend.key.height = unit(0.5 * as.numeric(t$legend.key.size),
                                         attr(t$legend.key.size, "unit")))
g + t2

May be I'm have missed a point.
Best regards,
Uwe

@hadley
Copy link
Member

hadley commented Jan 26, 2016

A considerably simpler reprex is:

df <- data.frame(x = 1:3, y = 1:3)
ggplot(df, aes(x, y, fill = factor(x))) + 
  geom_tile() + 
  theme(legend.key.height = 2 * unit(1, "lines"))

@hadley hadley added the bug an unexpected problem or unintended behavior label Jan 26, 2016
@hadley hadley added this to the v2.1.0 milestone Jan 26, 2016
@hadley hadley closed this as completed in c877eaf Jan 26, 2016
@lock lock bot locked as resolved and limited conversation to collaborators Jun 19, 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
Projects
None yet
Development

No branches or pull requests

2 participants