How can I remove the legend title in ggplot2?

前端 未结 6 518
面向向阳花
面向向阳花 2020-12-13 17:17

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:



        
6条回答
  •  旧巷少年郎
    2020-12-13 17:52

    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.

提交回复
热议问题