[R] filled bars with patterns

Paul Murrell p.murrell at auckland.ac.nz
Wed Mar 13 21:53:09 CET 2002


Hi


> > > yes, that's sort of what I was looking for. But I've to mix filled
bars
> > > with striped bars in a stacked barplot. I could just set the density
for
> > > the completely filled bars to something realy high (1000) but it's
realy
> > > slow to draw. Is there a way to mix stiped bars and filled pars in the
> > > same plot?
> >
> > There may be a better way, but does the following do the sort of thing
you
> > want ...?
> >
> > m <- matrix(runif(30), ncol=5)
> > barplot(m, beside=FALSE, col=rep(c("white", "light green", "pink"), 2),
> >         border=rep(c("white", "red"), 3), horiz=TRUE,
> >         xlim=c(0, 6), axes=FALSE)
> > par(new=TRUE)
> > barplot(m, beside=FALSE, col="blue",
> >         density=rep(c(10, 5, -1), 2),
> >         angle=rep(c(45, -45, 0), 2), horiz=TRUE,
> >         xlim=c(0, 6))
> >
> > Paul
>
>
> Hello,
>
> As far as I can see the above code plots two graphs, one with filled and
> one striped. I'd like to have filled and striped bars within the same
> stacked dataset of the same plot (e.g filled red bar, then striped red
> bar on top of the fileld red bar).
>
> But maybe I can alter your code so that I construct the plot bar by bar
> setting par(new = FALSE) (re-using the same plotting window). I'd have
> to recalculate the x-positions for all the bars that have to be on-top
> of the previous bars whenever I call barplot.


The code should work as-is.  It's not very intuitive, but par(new=TRUE)
actually means re-use the same plotting window.  And because the same data
is being plotted both times, the bars are drawn in exactly the same location
so there is no need for any recalculation of x-positions.

Paul


-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list