如何使用ggplot表示分类变量与连续变量?

时间:2017-10-18 04:35:28

标签: r plot ggplot2

我必须对具有值str_replace('中', '1', '中,博文大,精中深'); flag的分类变量Y绘制连续变量N。哪种情节最好?

Weight

1 个答案:

答案 0 :(得分:0)

尝试添加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)
)

,您的图表如下所示:

enter image description here