[R] multi-histogram plotting

David Winsemius dwinsemius at comcast.net
Tue Mar 13 22:53:14 CET 2012


On Mar 13, 2012, at 5:33 PM, Sam Steingold wrote:

> 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.

You could try apply a log transform to the appropriate component of  
the "h" object and using barplot to display the results.

-- 
David Winsemius, MD
West Hartford, CT



More information about the R-help mailing list