r - Plot of count data from table -


i have csv file containing approximately 2000 data points (counts) each of 10 samples:

3,1,3,2,2,2,0,... 2,0,0,1,3,2,1,... 3,0,3,0,3,1,0,... .... 

i used following view tabulated counts each sample:

x = read.csv('thefile.csv', header=false) table(as.numeric(x[1,]) table(as.numeric(x[2,]) table(as.numeric(x[3,]) 

i plot bar (or other) graph of tabulated counts samples, compare them. when tried test first 5 samples:

a = table(as.numeric(x[1,]) b = table(as.numeric(x[2,]) c = ... barplot(rbind(a,b,c,d,e)) 

i found values in graph misaligned, because not samples had same count values. value of "1" may absent in sample 2, example, resulting in no matching entry in tabulated results.

what best way plot these tabulated count data compare them visually?

reproducible data:

x <- replicate(10, round(10 * rexp(2000, 10))) 

as rightly note, frequency table each sample may not contain values.

apply(x, 2, table) ## [[1]]  ##   0   1   2   3   4   5   6   8  ## 771 798 274 104  37  14   1   1   ## [[2]]  ##   0   1   2   3   4   5   6  ## 792 788 275  77  37  26   5      ## etc. 

the trick convert each column of x factor possible values of x levels.

(y <- apply(x, 2, function(column) table(factor(column, levels = 0:9)))) ##   [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] ## 0  771  792  797  783  775  806  801  793  788   795 ## 1  798  788  795  744  792  738  765  720  729   760 ## 2  274  275  253  308  271  288  263  297  312   261 ## 3  104   77   91  110  104  114  103  117  106   124 ## 4   37   37   42   37   35   33   48   49   41    36 ## 5   14   26   16    8   11   16   12   15   17    14 ## 6    1    5    3    8    8    2    3    4    6     7 ## 7    0    0    3    1    3    3    2    1    1     1 ## 8    1    0    0    1    1    0    3    3    0     1 ## 9    0    0    0    0    0    0    0    1    0     1 

then can draw barplot

barplot(y) 

Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -