[R] problems on plotting adjacent bars with barplot. Help request, please
Giacomo Prodi
bonoricus at yahoo.it
Tue Jun 3 18:56:44 CEST 2008
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.
___________________________________
http://www.ymailblogit.com/blog/
More information about the R-help
mailing list