leoncio
November 19, 2020, 7:14am
1
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!
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
leoncio
November 19, 2020, 8:23am
3
Thanks!
Strangely, I got no warning.. Maybe some settings I am oblivious of being a newbie to R
(btw I've just learned that putting col="red" outside of aes() also eliminates the legend)
system
Closed
November 26, 2020, 8:23am
4
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.