remove legend title in ggplot

前端 未结 5 1771
死守一世寂寞
死守一世寂寞 2020-12-23 02:45

I\'m trying to remove the title of a legend in ggplot2:

df <- data.frame(
  g = rep(letters[1:2], 5),
  x = rnorm(10),
  y = rnorm(10)
)

lib         


        
5条回答
  •  情话喂你
    2020-12-23 03:05

    Since you may have more than one legends in a plot, a way to selectively remove just one of the titles without leaving an empty space is to set the name argument of the scale_ function to NULL, i.e.

    scale_fill_discrete(name = NULL)

    (kudos to @pascal for a comment on another thread)

提交回复
热议问题