Re: [R] barplot: different colors for the bar and the strips

From: Marc Schwartz (via MN) <mschwartz_at_mn.rr.com>
Date: Thu 07 Sep 2006 - 17:25:50 GMT

On Thu, 2006-09-07 at 12:14 -0500, Hao Chen wrote:
> Hello Marc Schwartz
>
> On Thu, Sep 07, 2006 at 07:54:05AM -0500, Marc Schwartz wrote:
> > On Thu, 2006-09-07 at 06:18 -0500, Hao Chen wrote:
> > > Hi,
> > >
> > > I am using barplot and would like to know if it is possible to have bars
> > > filled with one color while use a different color for the shading lines.
> > >
> > > The following code colors the shading lines, leaving the bars in white:
> > >
> > > barplot(1:5, col=c(1:5), density=c(1:5)*5)
> > >
> > > while the colors are applied to the bars when density is removed.
> > >
> > > barplot(1:5, col=c(1:5))
> > >
> > > I did check ?barplot and found the following:
> > >
> > > col: a vector of colors for the bars or bar components.
> > >
> > > Thanks,
> > >
> > > Hao
> >
> > Note the key word 'or' in the description of the 'col' argument.
> >
> > You need to make two separate calls to barplot(). The first using the
> > fill colors, then the second using the shading lines AND setting 'add =
> > TRUE', so that the second plot overwrites the first without clearing the
> > plot device.
> >
> > barplot(1:5, col=c(1:5))
> >
> > barplot(1:5, col = "black", density=c(1:5), add = TRUE)
> >
> > Just be sure that any other arguments, such as axis limits, are
> > identical between the two calls.
> >
> > HTH,
> >
> > Marc Schwartz
> >
>
>
> Thank you very much for your help. It works but only in the order as you
> put it, since the following code only shows the color, but not the
> shading lines:
>
> barplot(1:5, col = "black", density=c(1:5))
> barplot(1:5, col=c(1:5), add = TRUE)
>
> Hao Chen

That is correct. The sequence is important, as the shading lines are drawn with a transparent background, enabling the original color to be seen.

Reversing the order, you are overplotting the shading lines with opaque colored rectangles. Hence, the lines are lost.

HTH, Marc



R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Received on Fri Sep 08 09:06:19 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Thu 07 Sep 2006 - 23:30:06 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.