I want to produce a boxplot for multiple groups y with continuous x. I give an example as follows:
library(ggplot2)
ggplot(diamonds, aes(carat, price)) +
geom_boxplot(aes(group = cut_width(carat, 0.25), colour=color))
I get the figure as follow:
However, the 'colour' does not work here. Could anybody help me to fix this problem? Thanks in advance.
You need to also group by color (otherwise it will group different colors together):
ggplot(diamonds, aes(carat, price)) +
geom_boxplot(aes(group = interaction(cut_width(carat, 0.25), color), colour=color))
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