[R] stem - strange leaves

S Ellison S.Ellison at LGCGroup.com
Fri Feb 16 16:55:16 CET 2018


> > From: Leif Ruckman [mailto:leif.ruckman at kau.se]
> > Sent: Friday, February 16, 2018 3:27 PM
> > To: PIKAL Petr <petr.pikal at precheza.cz>
> > Subject: RE: stem - strange leaves
> >
> > Thank you, I also found that solution but I think it is strange that
> > this happens at all. I have tried different data and sometimes this
> > happens and sometimes it doesn't so I would like to understand why.

C code is at 
https://github.com/wch/r-source/blob/trunk/src/library/graphics/src/stem.c

stem() sets the bin width for a 'pretty' number of categories, taking some account of the number of data points. There are (inevitably) some  somewhat arbitrary choices in there about what looks right. But the important thing is that changing the number of items can trigger a threshold change in bin width. One of those triggers relies in part on >= tests applied to a value calculated (in part) from 150/(n + 50). That would be (within available precision) exactly 2 for n=25; slightly smaller for n=26.
In your case, your extra data point takes you from n=25 to n=26 values - in turn triggering a change in bin width for your particular data range. That in turn triggers a decimal place shift to leave two significant digits left of the '|' marker. 

Since all your data are rounded to the first decimal place, with an implied trailing zero, you only have zeroes after the first two significant digits. So - with due deference to 'California dreaming' - all the leaves are zero. 

Steve Ellison





*******************************************************************
This email and any attachments are confidential. Any use, copying or
disclosure other than by the intended recipient is unauthorised. If 
you have received this message in error, please notify the sender 
immediately via +44(0)20 8943 7000 or notify postmaster at lgcgroup.com 
and delete this message and any copies from your computer and network. 
LGC Limited. Registered in England 2991879. 
Registered office: Queens Road, Teddington, Middlesex, TW11 0LY, UK


More information about the R-help mailing list