1

I am trying to change the legend size of my ggplot2 plot and am running into an error about a missing function:

> xy <- data.frame(x=1:10, y=10:1, type = rep(LETTERS[1:2], each=5))
> plot <- ggplot(data = xy) + geom_point(aes(x = x, y = y, color=type))
> plot + theme(legend.key.width = unit(5, "cm"))
Error in theme(legend.key.width = unit(5, "cm")) : 
  could not find function "unit"

Am I missing something or is this a bug? I am running most recent versions:

> getRversion()
[1] ‘3.2.0’
> packageVersion('ggplot2')
[1] ‘1.0.1’
2
  • 4
    Try library (grid) Commented May 9, 2015 at 19:53
  • yep thats it, write it as an answer and I will accept it Commented May 9, 2015 at 19:55

1 Answer 1

3

unit is a function of the grid package. Just load library(grid), and it should work.

Edit: sorry, didn't see the comment, which already answered this question...

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.