简体   繁体   中英

ggplot boxplot multiple groups of y with continuous x

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))

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM