尝试添加fill = Data$Buy_Flag
,以便您的绘图代码如下所示:
qplot(
x = Data$Weight,
fill = Data$Buy_Flag,
geom = "histogram",
main = "Weight distribution for Y Goods",
binwidth = 0.5,
xlab = "Weight of Y Goods",
fill = I("blue"),
col = I("red"),
alpha = I(0.2),
xlim = c(0, 5)
)
,您的图表如下所示: