[R] multi-histogram plotting

Sam Steingold sds at gnu.org
Tue Mar 13 22:33:38 CET 2012


I have a vector x:
table(x)

    2     3     4     5     6     7     8     9    10    11    12    13    14 
45547 11835  4692  2241  1386   820   593   425   298   239   176   158   115 
   15    16    17    18    19    20    21    22    23    24    25    26    27 
   94    88    76    67    47    46    40    20    30    22    20    33    14 
   28    29    30    31    32    33    34    35    36    37    38    39    40 
   20    10    12    10    11     8     9     8     9     9     8     7     4 
   41    42    43    44    45    46    47    48    49    50    51    52    53 
    5     4     6     5     2     5     4     4     3     1     6     4     3 
   54    55    56    57    58    59    60    61    63    64    65    66    67 
    2     2     1     4     5     2     5     1     3     2     1     1     4 
   71    72    75    78    79    82    83    84    86    88    90    92    93 
    2     3     1     2     2     2     2     1     2     2     1     1     1 
   94    95    96    97    98    99   100   106   109   110   111   112   119 
    1     2     1     1     3     1     1     3     1     2     2     1     1 
  122   125   126   128   132   133   135   140   143   147   148   157   162 
    1     1     1     1     1     1     1     1     1     1     1     1     1 
  165   166   167   169   174   176   193   197   201   208   224   236   339 
    1     1     1     1     1     1     1     1     1     1     1     1     1 
  350   390   391   410   421   447   450   453   479   512   608   679   754 
    1     1     1     1     1     1     1     1     1     1     1     1     1 
  774   788   956   961  9597 14821 
    1     1     1     1     1     1 

I want to plot its histogram; moreover,
I want to plot histograms of its several subsets on the same device
(plot+lines+lines+... - right?)
This means that I need a freq=FALSE plots.
Now, a simple hist(x) produces a useless plot (vertical bar + horizontal
bar, which could be inferred from the table above).
So, I want
1. a logarithmic vertical scale
2. an "interesting" horizontal scale

so I do

h <- hist(x, freq=FALSE, breaks=c(1:20,25,30,40,60,100,100000), plot=FALSE)

now I plot h$density vs 1:length(h$mids) or against
h$mids[1:(length(h$mids)-1)] if I want to be honest,
but I still don't see how to effect a log vertical scale.
I can, of course, plot log(h$density), but then the number labels will be wrong.

thanks!

-- 
Sam Steingold (http://sds.podval.org/) on Ubuntu 11.10 (oneiric) X 11.0.11004000
http://www.childpsy.net/ http://iris.org.il http://www.memritv.org
http://dhimmi.com http://www.PetitionOnline.com/tap12009/
Procrastinate later.



More information about the R-help mailing list