簡體   English   中英

如何使用ggplot表示分類變量與連續變量?

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

我必須針對連續變量Weight繪制具有值YN分類變量flag 哪種情節最好?

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

嘗試添加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)
)

您的圖表如下所示:

在此處輸入圖片說明

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM