2013-06-12 26 views
1

我想爲因子變量「zip」的每個級別創建變量「billed」(數字,x軸)的27個直方圖( y軸是「計數」)。 「zip」有27個級別。爲具有各自的比例的變量(因子)的每個級別創建多個直方圖

有沒有辦法在一個圖形(3X9)上顯示27個直方圖,沒有重疊?

我試圖用這個GGPLOT2:

p<-ggplot(dat,aes(x=billed))+geom_histogram(aes(fill=zip),binwidth=1.5) 
+facet_wrap(~zip,ncol=9) 

新的問題是,所有這些直方圖具有相同的規模。但是我的數據的y軸/ x軸在不同的拉鍊之間有很大的不同。有沒有辦法根據自己的比例創建這些直方圖?

我不介意使用常規r函數,如果這也可以通過hist()實現,因爲ggplot2中的審美特徵對我的情況沒有用處。

+3

'facet_wrap(〜zip,ncol = 9,scales =「free」)'? – baptiste

+0

@baptiste是的,確切地說。 – kostia

回答

1
require(lattice) 
histogram(~ billed | zip , data=dat, 
      layout=c(3,9) , scales= list(y=list(relation="free"), 
             x=list(relation="free"))) 

#worked example from ?histogram page: 
histogram(~ height | voice.part, data = singer, 
      layout = c(2,4), scales=list(y=list(relation="free"), 
             x=list(relation="free"))) 
相關問題