Skip to content

filled bars with patterns

9 messages · Paul Murrell, Arne Mueller

#
Hello All,

I've created a view stacked barplots where some of the bars should 
contain a pattern such as stripes. Adjacent bars of the same stack 
should have the same colour but a different finnling pattern. Is R able 
to do that?

Anyway, it's not the end of the world if not, a workaround would be to 
export the plot in fig format and then using xfig to make the bar 
filling striped, dotted etc ...

		thanks for comments,

			Arne
1 day later
#
Hi
Take a look at the last example of example(barplot) -- is this the sort of
thing you want to do?

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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
#
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?

I've done something like this:

barplot(m, beside = FALSE, horiz = TRUE, density = c(-1,10,-1,10,-1,10),
	xlab = "fraction of genome",
	col = cols, xlim = c(0,100), axes = FALSE)

	thanks a lot,

	Arne
On Wed, 13 Mar 2002, Paul Murrell wrote:

            
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
#
Hi
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


-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
#
Paul Murrell wrote:
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.

	thanks for the suggestion,

	Arne
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
#
Hi
bars
for
realy
you
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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
#
Arne Mueller wrote:
Hi,

I'd also like to have the filled boxes in the legend to be striped. The
legend function has a 'density' attribute, but unfortunately this does't
seem to do anything

following the above example

legend(3.4, 5, c('Axx','Bxx','Cxx','Dxx'), fill = c('red', 'blue',
'green', 'orange'))

is the same as

 legend(3.4, 5, c('Axx','Bxx','Cxx','Dxx'), density=10, fill = c('red',
'blue', 'green', 'orange'),
      density=c(10,-1,20, 200))

In the above example R warns that 'border' is not used yet. Does that
change soon? Basically I'd like the border of each bar to be black
rather than the fill color.

However, isn't it a logic step to implement the density attribute of the
barplot in a way that one can mix filled bars with stiped bars? E.g

barplot(..., besides = FALSE, horiz = TRUE, col = c('red', 'blue',
'green', 'orange'),
	density = c(-1,0,-1,10))

where a density value of 0 means no density AND no filling (empty, just
border), a negative value means complete filling with no stipes and a
positve value means actually stiping with that density valie.

	regards,

	Arne
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
#
Hi


<snip>
This appears to be a bug.  Can you file a bug report for this please?
I'm not sure when this might get implemented properly -- in the meantime,
here's a small extension of the example that will "cheat" to give the effect
I think you want ...

 m <- matrix(runif(30), ncol=5)
 barplot(m, beside=FALSE, col=rep(c("white", "light green", "pink"), 2),
         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))
 par(new=TRUE)
 barplot(m, beside=FALSE, col="black", density=-1,
         horiz=TRUE,
         xlim=c(0, 6))
There are a number of places in R where several graphics parameters interact
with each other in a nasty way.  Suggestions for clarifications like this
are very welcome.  But even better would be a patch for the barplot code
that implemented the change :)

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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
#
Hi,

thanks for the hint, the workaround below works fine. I'll also file a
bug report on the density stuff in the legend call. 

	regards,

	Arne
Paul Murrell wrote:
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._