Hello, I have the following problem: I created an ecdf and a barplot. Unfortunatly, the bars are not where I would like them to be (please see picture below). http://www.nabble.com/file/p12877530/problem.gif That's my code: #------------------------ par(mfrow=c(2,1), mar=c(2,3,3,2)) #ECDF x = c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2) F2.5 <- ecdf(x) plot(F2.5, verticals= TRUE, do.p = TRUE, lwd=3, ylab = "", xlab = "", main = "Figur 2.12 Frequenztabelle und eVf", xlim = c(-1,4)) abline(h= (0:10)*0.1) mtext(text="x", side=1, adj = 1.03, padj=1.23, cex=1.2) mtext(text="f(x)", side=3, adj = -0.06, padj=-1, cex=1.2) par(mar=c(4,3,1,2)) #Barplot width<-c(0.4, 0.4, 0.4) height<-c(0.5, 0.35, 0.15) barplot(height,width,xlim=c(-1,4), space=1.5,) axis(side=1) #------------------------ Can anyone tell me how I can adjust the bars to the left? Thanks Tobias -- View this message in context: http://www.nabble.com/Adjust-barplot-to-the-left-tf4514904.html#a12877530 Sent from the R help mailing list archive at Nabble.com.
barplot(height,width,xlim=c(-1,4), space=c(-.5,1.5,1.5)) will do the trick. "space" is a relative parameter depending on "width" so you get 1.5*0.4=0.6 space and with width=0.4 you get an overall distance of 1 between to bars. hth. squall44 schrieb:> Hello, > > I have the following problem: I created an ecdf and a barplot. Unfortunatly, > the bars are not where I would like them to be (please see picture below). > > http://www.nabble.com/file/p12877530/problem.gif > > That's my code: > #------------------------ > par(mfrow=c(2,1), mar=c(2,3,3,2)) > > #ECDF > x = c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2) > F2.5 <- ecdf(x) > plot(F2.5, > verticals= TRUE, > do.p = TRUE, > lwd=3, > ylab = "", > xlab = "", > main = "Figur 2.12 Frequenztabelle und eVf", > xlim = c(-1,4)) > abline(h= (0:10)*0.1) > mtext(text="x", side=1, adj = 1.03, padj=1.23, cex=1.2) > mtext(text="f(x)", side=3, adj = -0.06, padj=-1, cex=1.2) > > par(mar=c(4,3,1,2)) > > #Barplot > width<-c(0.4, 0.4, 0.4) > height<-c(0.5, 0.35, 0.15) > barplot(height,width,xlim=c(-1,4), space=1.5,) > axis(side=1) > #------------------------ > > Can anyone tell me how I can adjust the bars to the left? > Thanks > > Tobias >-- Eik Vettorazzi Institut f?r Medizinische Biometrie und Epidemiologie Universit?tsklinikum Hamburg-Eppendorf Martinistr. 52 20246 Hamburg T ++49/40/42803-8243 F ++49/40/42803-7790
squall44 wrote:> Hello, > > I have the following problem: I created an ecdf and a barplot. Unfortunatly, > the bars are not where I would like them to be (please see picture below). > > http://www.nabble.com/file/p12877530/problem.gif > ... > > Can anyone tell me how I can adjust the bars to the left?Hi Tobias (and anyone else who is interested), This is a rather intriguing request. If there are people out there who would like to place the bars in a barplot at arbitrary positions, I could rather easily modify "barp" in the plotrix package to do this. (I've already tried it with the "xpos" argument as a test, and it produces nice overlapped bars, if you like that sort of thing.) However, as a one-off, I would probably not include it in plotrix. I attach the perhaps buggy altered code for Tobias if it helps. Use it instead of barplot like this: library(plotrix) # add your path to the barp.R file to the following source("barp.R") barp(height,width=0.2,col="gray",xlim=c(-1.2,4.2),xpos=0:2) If I get a few requests, I can thrash the code a bit and it will turn up in the next version of plotrix. Jim -------------- next part -------------- An embedded and charset-unspecified text was scrubbed... Name: barp.R Url: https://stat.ethz.ch/pipermail/r-help/attachments/20070925/4758ef5a/attachment.pl