[R] Is there a problem with lattice axes?

(Ted Harding) Ted.Harding at manchester.ac.uk
Sun Dec 27 00:21:30 CET 2009


OK, I take it all back" (See original below). I had overlooked

A: That the Y Label for the histograms I drew was
   "Percent of Total", and that there is a parameter 'type
   for which type="percent" is the default.

B: That the histograms I used as an example had N=100 for
   the case with largest N, so in that case the percentages
   were the same as the counts, and hence not diagnostic.

The proper solution (giving rise to the outcome "A:" which
I describe at the end) is to use type="count".

Apologies for the noise!
Ted.

On 26-Dec-09 22:03:48, Ted Harding wrote:
> Thanks, Dennis, that does it! And, now that you have pointed
> it out, I finally found that particular case lurking deep in
> "?xyplot".
> 
> This still leaves the question: When the (default) "same" is
> used, why does histogram() plot the bar-heights as if "free"
> had been used? The result is that all but one of the histograms
> would be read on the wrong scale. If that were the information
> one supplied to someone else, to represent count data, without
> indicating that this was happening, then the reader would be
> misled about the numbers.
> 
> Ted.
> [copying my reply above to a private response also to the list]
> 
> On 26-Dec-09 20:38:28, Dennis Murphy wrote:
>> scales = free, perhaps?
>> 
>> On Sat, Dec 26, 2009 at 12:07 PM, Ted Harding
>> <Ted.Harding at manchester.ac.uk>wrote:
>> 
>>> After answering a previous post by James Rome:
>>> "Re: [R] Why do histogram bars vary their width?"
>>>
>>> I noticed that the lateral axis scales in the lattice histogram
>>> which I used for illustration are inconsistent with the frequencies.
>>> The example was:
>>>
>>> set.seed(54321)
>>>  X <- c(rnorm(100),rnorm(50,1.0,0.5),rnorm(25,-1.0,0.5),rnorm(10))
>>>  F <- factor(c(rep(0,100),rep(1,50),rep(2,25),rep(3,10)))
>>> # The default:
>>>  histogram(~X | F)
>>> # Your choice (number of breaks)
>>>  histogram(~X | F, breaks=10)
>>> # Explicit specification of break-points:
>>>  histogram(~X | F, breaks=0.5*(-6:6))
>>>
>>> In the third of these, you will see that the frequency scales are
>>> marked at marked at 0,10,20,30,40,50 throughout. This is appropriate
>>> for the bottom-left histogram (Level of F=0, N=100), and the
>>> displayed frequencies do indeed (by eye) seem to add up to 100.
>>> It is certainly not right for the top-right histogram (F=3,N=10),
>>> where the displayed scale needs to be 0,1,2,3 (giving 1+3+5+1=10),
>>> i.e. divided by 10; but at least this one is readily re-scalable
>>> "by eye". However, it is neither right nor readily re-scalable
>>> for the other two:
>>>
>>>  F=1, N=50, apparent sum = 2+10+44+22+18+4=100
>>>  F=2, N=25, apparent sum = 8+32+48+12     =100
>>>
>>> Clearly, while in principle it would be possible to have
>>>  A: an axis lower-left  (F=0,N=100) scaled 0,10,  20,  30,  40,  50
>>>  B: an axis lower-right (F=1,N= 50) scaled 0, 5,  10,  15,  20,  25
>>>  C: an axis upper-left  (F=2,N= 25) scaled 0, 2.5, 5.0, 7.5,10.0,12.5
>>>  D: an axis upper-right (F=3,N= 10) scaled 0, 1,   2,   3,   4,   5
>>> in this 2x2 case, it could not work for say a 3x3 lattice.
>>>
>>> The right thing to do when there is a common vertical scale
>>> along a row is to scale each plot itself accordinng to the
>>> vertical scale for the row. Instead, it seems to have chosen
>>> a vertical scale for each histogram as plotted so that the
>>> histiogram bars will nicely fill the panel window in each case,
>>> disregarding the vertical scaling which has been determined
>>> according to the histogram with the largest N.
>>>
>>> Thus one could have a scale 0,10,20,30,40 for the bottom row,
>>> with the lower right-hand histogram bars being half the height
>>> they have as displayed by the above, and either
>>>  A: the same scale for the upper row as for the bottom row,
>>>     but with the left-hand histogram bars 1/4 the height
>>>     and the right-hand histogram bars 1/10 the height
>>> or
>>>  B: a scale 0,2.5,5.0,7.5,10 with the left-hand histogram
>>>     bars just as they are now, and the right-hand histogram
>>>     bars 1/2.5 the hright.
>>>
>>> Or maybe there is an option lurking somewhere in the lattice
>>> documentation which looks after this sort of thing -- but I
>>> have not been able to find it despite have spent some time
>>> searching.
>>>
>>> R version 2.10.0 (2009-10-26)
>>> lattice version: 0.17-26 (2009/10/05)
>>>
>>> Ted.

--------------------------------------------------------------------
E-Mail: (Ted Harding) <Ted.Harding at manchester.ac.uk>
Fax-to-email: +44 (0)870 094 0861
Date: 26-Dec-09                                       Time: 23:21:27
------------------------------ XFMail ------------------------------




More information about the R-help mailing list