[R] Label / Tick under single Boxplot

Marc Schwartz MSchwartz at MedAnalytics.com
Wed Apr 20 15:49:05 CEST 2005


On Wed, 2005-04-20 at 11:08 +0100, Prof Brian Ripley wrote:
> On Wed, 20 Apr 2005, Werner Wernersen wrote:
> 
> > I also tried to look into the source code of boxplot()
> > but when I type "boxplot"
> > R returns only
> >
> > function (x, ...)
> > UseMethod("boxplot")
> > <environment: namespace:graphics>
> >
> > instead of the full source code as other function like
> > colSums do.
> 
> That is `the full source code' of boxplot!
> 
> Please do read `An Introduction to R' and so find out about generic 
> functions.
> 
> > How did you find out about bxp?
> 
> I believe Marc read the documentation: ?boxplot has a link to ?bxp and 
> documents its own methods.  That's a good example to emulate.

Indeed.

This is also, I believe, a good reflection of sensible defaults in R.
The question to ask here would be "Why would there be a check to see if
there is only one box to be plotted and therefore, by default, not show
a group name?"

In this case, with a single box, there is (subject to personal opinion)
no need to label a single box, when the title of the plot can be worded
to satisfactorily describe what is being presented. One does not need to
differentiate multiple boxes with colors and labels, etc.

If however, one wants to go beyond the default behavior and modify it to
one's liking, then one needs to "look under the hood [bonnet]" to
understand how R behaves. 

Not that I am fully cognizant of it all, but at least understanding how
R uses methods and the general design philosophy of using more compact
functions to handle specific tasks is important. When these more compact
functions are used in combination, they create more powerful higher
level abilities and also enhance flexibility. This is in contrast to
creating huge monolithic functions that do one thing well, but restrict
the ability to re-use and extend functionality in a simple fashion.

It is this approach that underlies Martin's example in his reply, of
using boxplot() to simply calculate the summary statistics (which is
actually done by boxplot.stats() as referenced in ?boxplot) without
plotting them and then to call bxp() directly, which enables you to
modify the default plot behavior.

HTH,

Marc Schwartz




More information about the R-help mailing list