r - barplot two-sided data sets left and right of y axis -


i trying figure out how make barplot can show 2 data sets. each @ 1 side of y-axis. need space showing many data sets in few graphs. stacked or besides other options find out how solve task specially have started play around little

#creating data     names<-letters[1:9]  data1<-c(8, 6, 3, 2, 0, 1, 1, 3, 1) data2<-c(0, -1,  0,  0,  0,  0,  0, -2, -1)#negative show them on                                             #left side of yaxis  data1<-matrix(data1,ncol=9,nrow=1,byrow=f) dimnames(data1)<-list(1,names)  data2<-matrix(data2,ncol=9,nrow=1,byrow=f) dimnames(data2)<-list(1,names)  par(fig=c(0.5,1,0,1)) # making space "left" barplot barplot(data1,horiz=t,axes=t,las=1) par(fig=c(0.35,0.62,0,1), new=true)#adjusting "left" barplot  #because labels negative  # use of axes=f barplot(data2,axes=f,horiz=t,axisnames=false) #creating new axis desired labels axis(side=1,at=seq(-8,0,2),labels=c(8,6,4,2,0)) 

but have difficulties understand concept behind fig=c(...) how can ad xaxis "left" barplot has same lenght i.e running 0:8 other one

thanks alex

as long know axes before hand, should work (adding in xlim argument).

i edited earlier code bit, how think want output look:

par(mfrow=c(1,2)) barplot(data2,axes=f,horiz=t,axisnames=false,         xlim=c(-8,0))  #creating new axis desired labels axis(side=1,at=seq(-8,0,2),labels=c(8,6,4,2,0)) barplot(data1,horiz=t,axes=t,las=1) 

Comments

Popular posts from this blog

css - Which browser returns the correct result for getBoundingClientRect of an SVG element? -

gcc - Calling fftR4() in c from assembly -

Function that returns a formatted array in VBA -