How can I:
Change the legend text from "0", "1" to something else?
require(ggplot2)
ggplot(mtcars, aes(factor(cyl), mpg)) +
geom_boxplot(aes(fill=factor(vs), colour=c("grey50", "white")))
Instead of the colour aesthetic, you want to adjust the fill aesthetic. You can handle both of your questions (and much more) by adjusting the scale:
ggplot(mtcars, aes(factor(cyl), mpg, fill = factor(vs))) +
geom_boxplot() +
scale_fill_manual(name = "This is my title", values = c("pink", "green")
, labels = c("0" = "Foo", "1" = "Bar"))
The ggplot2 website help page for scale_manual is full of good examples.
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