2013-03-28 54 views
1

我打算讓像堆巴圖在這個崗位 plot stacked bar plot in R使每個錶行的垃圾箱和借鑑棧欄圖中的R

我在表格格式的原始數據,而無需任何所有權(這每一行包含七個值):

1.028 1.125 1.475 0.793 0.803 0.815 0.974 
0.867 1.115 1.256 1.377 1.029 1.184 1.135 
0.497 0.400 0.313 0.570 0.319 0.558 0.475 
0.541 0.646 0.309 0.692 0.813 0.575 0.806 
1.153 1.184 0.792 0.666 0.976 0.607 0.706 
1.236 1.049 1.424 1.773 1.019 0.910 1.376 

我的計劃是首先爲每一行創建不同步長爲1的區間。

0-1 1-2 2-3 
4 3 0 
1 6 0 
... 

秒,使x軸的每一行的間隔的堆棧欄。

我做了大量的谷歌搜索。我在這裏停止....

> mytable = read.table("./temp.out") 
> m <-apply(mytable, 1, cut, seq(0, 3, 1)) 
> m 
[,1] [,2] [,3] [,4] [,5] [,6] [,7] 
[1,] "(1,2]" "(0,1]" "(0,1]" "(0,1]" "(0,1]" "(1,2]" "(1,2]" 

[2,] "(1,2]" "(1,2]" "(0,1]" "(0,1]" "(0,1]" "(1,2]" "(1,2]" 

[3,] "(1,2]" "(1,2]" "(0,1]" "(0,1]" "(0,1]" "(0,1]" "(1,2]" 

[4,] "(0,1]" "(1,2]" "(0,1]" "(0,1]" "(0,1]" "(0,1]" "(1,2]" 

[5,] "(0,1]" "(1,2]" "(0,1]" "(0,1]" "(0,1]" "(0,1]" "(1,2]" 

[6,] "(0,1]" "(1,2]" "(0,1]" "(0,1]" "(0,1]" "(0,1]" "(0,1]" 

[7,] "(0,1]" "(1,2]" "(0,1]" "(0,1]" "(0,1]" "(0,1]" "(1,2]" 

後,我無法在頻率錶轉換這是

0-1 1-2 2-3 
4 3 0 
1 6 0 
... 

你能不能給我建議頻率表如何進行? 獲得頻率表後,這些數據可以繪製在堆棧欄中?

回答

0

你可以得到你想要的,象這樣一個匿名函數的信息:

m <- t(apply(mytable, 1, function(x) table(cut(x,seq(0, 3, 1))))) 

> m 
    (0,1] (1,2] (2,3] 
[1,]  4  3  0 
[2,]  1  6  0 
[3,]  7  0  0 
[4,]  7  0  0 
[5,]  5  2  0 
[6,]  1  6  0 

如果你留在轉格式的數據,而不t是這樣的...

m <- apply(mytable, 1, function(x) table(cut(x,seq(0, 3, 1)))) 

。 ..你可以只是barplot,因爲它是:

barplot(m) 
+0

非常感謝。有用。 – Exchhattu 2013-03-28 02:09:44

+0

@Exchhattu - 沒問題 - 如果是這種情況,請點擊此答案旁邊的勾號,以便此問題的未來觀衆知道這是被接受的答案。 – thelatemail 2013-03-28 02:13:07

+0

你能幫忙把傳說嗎? – Exchhattu 2013-03-28 02:49:45