[R] dimensions of stacked barplot
Ben Bolker
ben at zoo.ufl.edu
Mon Jan 14 16:27:20 CET 2002
No-one seems to have answered this yet, hope it's useful. You could
easily encapsulate this into a function if you wanted.
## barplot with dotted lines
tmp <- matrix(runif(30),nrow=5)
defspace <- 0.8
b <- barplot(tmp,beside=FALSE,space=defspace)
mid <- (b[-1]+b[-length(b)])/2
e1 <- mid-defspace/2
e2 <- mid+defspace/2
nr <- nrow(tmp)
nc <- ncol(tmp)
xpos1 <- rep(e1,rep(nr,length(e1)))
xpos2 <- rep(e2,rep(nr,length(e2)))
tmpcum <- apply(tmp,2,cumsum)
ypos1 <- tmpcum[,-nc]
ypos2 <- tmpcum[,-1]
segments(xpos1,ypos1,xpos2,ypos2,lty=2,col=4)
On Tue, 8 Jan 2002, Michael D. Sohn wrote:
>
> I'm plotting stacked barplots using:
>
> > barplot(tmp, beside=F)
>
> This gives me several stacked bars. Each stack is divided into several
> segments. I'd like to add a dotted line from the edge of one segment to
> the same edge on the next stacked bar. This might help to see which
> stack shrinks or expands from one stacked bar to the next.
>
> I'm thinking that I could overlay dotted lines on the barplot. Is there
> an easier way? If not, how do I get the location of each of the
> segments?
>
> thanks,
> Mike
>
>
> -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
> 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
> _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
>
--
318 Carr Hall bolker at 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
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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