[R] barplot default colors

Marc Schwartz mschwartz at medanalytics.com
Wed Feb 5 17:14:02 CET 2003


>-----Original Message-----
>From: r-help-admin at stat.math.ethz.ch 
>[mailto:r-help-admin at stat.math.ethz.ch] On Behalf Of Liaw, Andy
>Sent: Wednesday, February 05, 2003 7:00 AM
>To: 'r-help at stat.math.ethz.ch'
>Subject: [R] barplot default colors
>
>
>Dear R-help,
>
>Can some one explain why barplot() uses changing colors in the 
>bars by default?  I should think that most of the time when 
>people draw barplots, they want the bars to be in the same 
>color.  (At least that's what I'd expect.  The first time I 
>used barplot() in R, I was shocked to see the
>colors.)  As an example, one example in ?layout draws a 
>scatterplot with histograms drawn on the margins.  The 
>histograms were drawn by barplot(), and, IMHO, look rather 
>hideous in the colors.
>
>Regards,
>Andy
>
>Andy I. Liaw, PhD
>Biometrics Research          Phone: (732) 594-0820
>Merck & Co., Inc.              Fax: (732) 594-1565
>P.O. Box 2000, RY84-16            Rahway, NJ 07065
>mailto:andy_liaw at merck.com

Andy,

This is an extrapolation beyond known data by me, but I would suspect
that one plausible reason is that since barplot can do grouped bars
and stacked bars, the original author decided to set a single default
multiple color vector for all cases. 

This would be one approach rather than checking to see what type of
barplot was being drawn and using a single color for the scenario you
are using or a multiple color vector for grouped/stacked bars.

It is obviously easy enough to add 'col = "color"' to the barplot()
arguments to use a single color of your choosing or an alternate
multiple color vector.

To change the default behavior now would likely break other code in
use.

My two cents....

Regards,

Marc Schwartz




More information about the R-help mailing list