單組直方圖
library(gcookbook)
library(ggplot2)
ggplot(faithful, aes(x=waiting)) +geom_histogram(binwidth=8, bins=10,fill="white", colour="black")
#改為8組 binwidth設置組距;origin設置分組原點
分組直方圖
library(MASS)
ggplot(birthwt, aes(x=bwt))+geom_histogram(fill="white",bins=10, colour="black")+facet_grid(smoke ~ .) 以smoke變量進行分類,做多個圖形,非一個圖形中做多個直方圖。如果變量為數字,應當因子化。
修改分類標簽:revalue(x, c("0"="No smoke","1"="smoke"))
參數scales = free可以單獨設定各個分面的Y軸標度。