1
votes

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’
1
Try library (grid) - Sandy Muspratt
yep thats it, write it as an answer and I will accept it - Stedy

1 Answers

3
votes

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