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)
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)
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
For your example case, you can use theme()
ggplot(mtcars, aes(mpg, wt, fill = mpg)) +
geom_bar(stat = "identity") +
theme(legend.position = 'none')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With