I have a question concerning the legend in ggplot2.

Say I have a hypothetical dataset about mean carrot length for two different colours at two farms:

```
carrots<-NULL
carrots$Farm<-rep(c("X","Y"),2)
carrots$Type<-rep(c("Orange","Purple"),each=2)
carrots$MeanLength<-c(10,6,4,2)
carrots<-data.frame(carrots)

```

I make a simple bar plot:

```
require(ggplot2)
p<-ggplot(carrots,aes(y=MeanLength,x=Farm,fill=Type)) + 
geom_bar(position="dodge") +
opts(legend.position="top")
p

```

My question is: is there a way to remove the title ('Type') from the legend?

Thanks!
['https://Stackoverflow.com/questions/6022898', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/745027/']
You can modify the legend title by passing it as the first parameter to a scale. For example:

```
ggplot(carrots, aes(y=MeanLength, x=Farm, fill=Type)) + 
  geom_bar(position="dodge") +
  theme(legend.position="top", legend.direction="horizontal") +
  scale_fill_discrete("")

```

There is also a shortcut for this, i.e. `labs(fill="")`

Since your legend is at the top of the chart, you may also wish to modify the legend orientation. You can do this using `opts(legend.direction="horizontal")`.

![enter image description here](https://i.stack.imgur.com/VOdR7.png)
You've got two good options already, so here's another using `scale_fill_manual()`. Note this also lets you specify the colors of the bars easily:

```
ggplot(carrots,aes(y=MeanLength,x=Farm,fill=Type)) + 
  geom_bar(position="dodge") +
  opts(legend.position="top") +
  scale_fill_manual(name = "", values = c("Orange" = "orange", "Purple" = "purple"))

```

If you are using the up-to-date (As of January 2015) version of ggplot2 (version 1.0), then the following should work:

```
ggplot(carrots, aes(y = MeanLength, x = Farm, fill = Type)) +
  geom_bar(stat = "identity", position = "dodge") +
  theme(legend.position="top") +
  scale_fill_manual(name = "", values = c("Orange" = "orange", "Purple" = "purple"))

```