ggplot show.legend not working for histogram

Hello,
I cannot turn off showing useless legend in the following example:

ggplot(mtcars) + 
  geom_histogram(aes(wt,..density.., col="red", show.legend=FALSE))+
  theme_minimal()

However, I've found it does work in the code below:

ggplot(mtcars) + 
  geom_histogram(aes(wt,..density.., col="red"))+
  theme_minimal()+ 
  theme(legend.position="none")

Is there some kind of a coding error in the first example?

Indeed there is an error! :wink:
The show.legend=FALSE needs to be outside the aes() brackets.
This works fine!

 ggplot(mtcars) + 
  geom_histogram(aes(wt,..density.., col="red"), show.legend=FALSE)+
  theme_minimal()

PS: There is a warning telling you something is wrong:
Warning: Ignoring unknown aesthetics: show.legend

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.

Thanks!
Strangely, I got no warning.. Maybe some settings I am oblivious of being a newbie to R :wink:
(btw I've just learned that putting col="red" outside of aes() also eliminates the legend)