[英]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
绘制具有值Y
和N
分类变量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.