# [R] problems on plotting adjacent bars with barplot. Help request, please

From: Giacomo Prodi <bonoricus_at_yahoo.it>
Date: Tue, 03 Jun 2008 18:56:44 +0200 (CEST)

hi ladyes and gentlemans of the R comunity. i have the following graphical issue:

# say y is a matrix or a dataframe with
dim(51,nrow=17),hence 3 columns;
l<-51

# now the 3 colums represents 3 different aspects of
my continuous variable (3 factors),plotted against a categorical one;
n<-levels(factor(x))

# i want to plot those 3 factors adjacently using the
barplot(), and possibly show error bars as well; err<-rep(1.2,17)

this is the function that i unsuccesfully wrote to do this:

adj.bars<-function(y,e,n,l){
both<-numeric(l)

```both[1:l%%2==1]<-y[,1]
both[1:l%%2!=c(0,1)]<-y[,2]
both[1:l%%2==0]<-y[,3]
```

labels<-character(l)
labels[1:l%%2==1]<-n
xv<-barplot(both,col=rep(c(1,2,3),17),
ylim=c(0,max(y)+e[1]),names=labels)
up<-x[,1]+e
down<-x[,1]-e
arrows(xv,up,xv,down,code=3,angle=90,length=0.025) up2<-x[,2]+e
down2<-x[,2]-e
arrows(xv,up,xv,down,code=3,angle=90,length=0.025) up3<-x[,3]+e
down3<-x[,3]-e
arrows(xv,up,xv,down,code=3,angle=90,length=0.025) }

i guess the "both" instruction is fake 'cause the plot looks really wrong.
i have also tried this other one.

rm(l)
l<-17
adj.bars<-function(y,e,n,l){
both<-rep(c(1,1.5,2),l)

```both[1:l%%2==1]<-y[,1]
both[1:l%%2==1.5]<-y[,2]
both[1:l%%2==0]<-y[,3]
```

...........

i thank you all for the attention, and i'll be grateful if someone had simple tip to all this. FEDERICO, undergraduate student in Insubria University Varese, Italy.

R-help_at_r-project.org 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 Tue 03 Jun 2008 - 19:42:55 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Tue 03 Jun 2008 - 20:30:45 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.