2017-10-18 174 views
-3

我必須對連續變量Weight繪製具有值YN的分類變量flag。哪種情節最好?如何用ggplot表示分類變量與連續變量?

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)) 
+0

家庭作業的問題不應該在這裏問。網上詳細介紹了大量的材料,適用於繪製分類變量和連續變量的圖表類型。你甚至試圖找出它? – Ashish

+0

@ Ashish,首先我不是學生。 –

+0

plot1 = qplot(X =數據$重量, 的geom = 「直方圖」, 主要= 「住宅商品重量分配」, binwidth = 0.5, xlab = 「住宅商品的重量」, 填充= I(」藍色「), col = I(」red「), alpha = I(0.2), xlim = c(0,5)) 但我無法將兩者結合。 –

回答

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