简体   繁体   中英

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 . 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:

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:

在此处输入图片说明

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