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 ------------------------------------------------------------------------------
>-----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.comAndy, 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
On Wed, 5 Feb 2003, Liaw, Andy wrote:> 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.The changing colours are useful when the data are a matrix (so that you have bars either stacked or in groups). You can easily get a single color, eg data(VADeaths) barplot(VADeaths, beside=TRUE, col="thistle") The colours themselves are definitely not ideal. As Paul Murrell said at the beginning of his talk on colour at last year' JSM "The only word for this is `embarassing'". Better colour palettes are in the works, eg see the RColorBrewer package. -thomas
> From: Thomas Lumley [mailto:tlumley at u.washington.edu] > > On Wed, 5 Feb 2003, Liaw, Andy wrote: > > > 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. > > The changing colours are useful when the data are a matrix > (so that you > have bars either stacked or in groups). You can easily get a single > color, > eg > data(VADeaths) > barplot(VADeaths, beside=TRUE, col="thistle")In that case, couldn't the code check whether the input is a matrix, and only use the changing colors if it is, and use only one color if the input is a vector (w/o dimensions)? Getting all bars to have the same color is easy. My gripe is that it's not the default, which surprised me. In the danger of taking this a bit off-topic, are there any "guidelines" on what aspect of R should and should not be compatible with Splus? barplot() in Splus does not use varying colors for the bars by default. Meanwhile, lattice uses the gray background / light blue foreground theme from Trellis as default, for the supposed compatibility with Splus. Personally I hated that color-scheme (because of my poor eye-sight and colorblind), but thought that compatibility with S is a rather weak reason there... OK, I guess enough venting for the day... Cheers, Andy [...] ------------------------------------------------------------------------------
[Taking this to R-devel]> In the danger of taking this a bit off-topic, are there any "guidelines" on > what aspect of R should and should not be compatible with Splus? barplot() > in Splus does not use varying colors for the bars by default. Meanwhile, > lattice uses the gray background / light blue foreground theme from Trellis > as default, for the supposed compatibility with Splus. Personally I hated > that color-scheme (because of my poor eye-sight and colorblind), but thought > that compatibility with S is a rather weak reason there...Cf. my comments last week about test procedures for GLMs with overdispersion. I don't at all mind non-compatibility with S-PLUS (I don't use it any more myself), especially for good reason; I can also appreciate not wanting to match the changing inconsistencies of some areas in S-PLUS. It would be nice to be able to flag areas that are known to be different, though.> > OK, I guess enough venting for the day... > > Cheers, > Andy > > [...] > > ------------------------------------------------------------------------------ > > ______________________________________________ > R-help@stat.math.ethz.ch mailing list > http://www.stat.math.ethz.ch/mailman/listinfo/r-help >-- 318 Carr Hall bolker@zoo.ufl.edu Zoology Department, University of Florida http://www.zoo.ufl.edu/bolker Box 118525 (ph) 352-392-5697 Gainesville, FL 32611-8525 (fax) 352-392-3704