简体   繁体   English

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

[英]How to represent categorical variable vs Continuous variable using ggplot?

I have to plot categorical variable flag having values Y and N against continuous variable Weight .我必须针对连续变量Weight绘制具有值YN分类变量flag Which is best kind of plot?哪种情节最好?

qplot(x=Data$Weight, 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))

try adding fill = Data$Buy_Flag so your plot code looks like this:尝试添加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)
)

and your graph looks like this:您的图表如下所示:

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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