How can I remove the legend title in ggplot2?
The only way worked for me was using legend.title = theme_blank()
and I think it is the most convenient variant in comparison to labs(fill="")
and scale_fill_discrete("")
, which also could be useful in some cases.
ggplot(carrots,aes(y=MeanLength,x=Farm,fill=Type)) +
geom_bar(position="dodge") +
opts(
legend.position="top",
legend.direction="horizontal",
legend.title = theme_blank()
)
P.S. There are more useful options in documentation.
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")
.
I found that the best option is to use + theme(legend.title = element_blank())
as user "gkcn" noted.
For me (on 03/26/15) using the previously suggested labs(fill="")
and scale_fill_discrete("")
remove one title, only to add in another legend, which is not useful.
You can use labs
:
p + labs(fill="")