2

Suppose for example I have

ggplot(data=PlantGrowth, aes(x=group, y=weight, fill=group)) + geom_boxplot()

and I don't want to display the legend. What is the simplest way to hide or remove the legend from a plot?

Fela
  • 26,730
  • 8
  • 26
  • 24
  • 1
    Why did you even ask this question if you were able to answer it yourself? – Jaap May 15 '14 at 15:23
  • 4
    @Jaap: that is actually [encouraged](http://meta.stackoverflow.com/questions/250204/can-you-answer-your-own-questions-on-stack-overflow) on SO -- although perhaps not if the question is itself a duplicate ... – Ben Bolker May 15 '14 at 15:35
  • 2
    I couldn't find an answer here, so when I figured it out I thought the answer could be helpful for others – Fela May 15 '14 at 15:38

1 Answers1

11

Add theme(legend.position="none"), like this:

ggplot(data=PlantGrowth, aes(x=group, y=weight, fill=group)) + 
  geom_boxplot() + 
  theme(legend.position="none")

(source)

Fela
  • 26,730
  • 8
  • 26
  • 24