Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Drop legend using show.legend = FALSE does not work on a continuous aesthetic

Tags:

r

ggplot2

I try to drop the legend by setting show.legend = FALSE. It works as expected when the fill variable is discrete:

library(ggplot2)
ggplot(mtcars, aes(x = mpg, y = wt, fill = factor(mpg))) +
  geom_bar(stat = "identity", show.legend = FALSE)

enter image description here However, when fill is mapped to a continuous variable, show.legend = FALSE does not drop the legend:

ggplot(mtcars, aes(x = mpg, y = wt, fill = mpg)) + 
   geom_bar(stat = "identity", show.legend = FALSE) 

enter image description here

Why doesn't show.legend = FALSE omit the legend for a continuous scale? How can I solve this?

I have ggplot2 v.2.0.0 (author: Hadley Wickham)

Reference: http://docs.ggplot2.org/current/geom_bar.html

like image 858
PatrickT Avatar asked Mar 03 '16 22:03

PatrickT


1 Answers

For your example case, you can use theme()

ggplot(mtcars, aes(mpg, wt, fill = mpg)) + 
  geom_bar(stat = "identity") +
  theme(legend.position = 'none')
like image 144
arvi1000 Avatar answered Sep 24 '22 07:09

arvi1000