I'm working up a set of small working examples in R to show what various distributions are and the beauty of the central limit theorem. Those example programs are in this directory: http://lark.cc.ukans.edu/~pauljohn/R/ExampleCode/ You can feel free to use those if you want, or you can send me other small working example code for R. The key here is small, self contained things that show things that R can do and people can run without too much trouble. Anyway, I have hit these problems (questions) 1. When I use paste to edit a title, it inserts spaces where I don't want them. See the picture here: http://lark.cc.ukans.edu/~pauljohn/R/ExampleCode/gamma4.png and note that, after the equal signs and the number 1, there is a space inserted whenever there is a comma separating text from variable. The code in question is: http://lark.cc.ukans.edu/~pauljohn/R/ExampleCode/template_gamma4.r the line I use to set the title is: oneHist <- hist(oneGamma,main=paste("here is one sample from your gamma(sh=",sh,",sc=",sc,")")) 2. Background tint in png output varies in a way I can't understand. One time I set up a png device and ran the plot and saved it: http://lark.cc.ukans.edu/~pauljohn/R/ExampleCode/gamma4.png Another time I forgot to turn on the device, ran the plot, then used dev.copy(png, file="poissonCLT",width=500,height=1000) to get: http://lark.cc.ukans.edu/~pauljohn/R/ExampleCode/poissonCLT.png in the poissonCLT.png, to my eye the background is light green, while in the gamma4.png, it is white. DO you see it too? 3. In all of these examples, I have had trouble positioning text in figures. Because I don't know what the plotted values will be until the model is run, it is hard to write coordinates for text(x,y,""). I frequently wish there were a way to say "top left part of graph", but the best i can come up with is to find the coordinates of the max or min values of x and y and put the text there. I have that code in the bottom of this one: http://lark.cc.ukans.edu/~pauljohn/R/ExampleCode/template_poisson4.r After using Axum for years, this seems a bit odd to me, but I'm willing to do it, if that is what you really intend us to do. -- Paul E. Johnson email: pauljohn at ukans.edu Dept. of Political Science http://lark.cc.ku.edu/~pauljohn University of Kansas Office: (785) 864-9086 Lawrence, Kansas 66045 FAX: (785) 864-5700 -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Paul Johnson wrote:>[...]> Anyway, I have hit these problems (questions) > > 1. When I use paste to edit a title, it inserts spaces where I don't > want them. > > See the picture here: > > http://lark.cc.ukans.edu/~pauljohn/R/ExampleCode/gamma4.png > > and note that, after the equal signs and the number 1, there is a space > inserted whenever there is a comma separating text from variable. The > code in question is: > > http://lark.cc.ukans.edu/~pauljohn/R/ExampleCode/template_gamma4.r > > the line I use to set the title is: > > oneHist <- hist(oneGamma,main=paste("here is one sample from your > gamma(sh=",sh,",sc=",sc,")"))See ?paste, what you want is : paste(..., sep="")> 2. Background tint in png output varies in a way I can't understand. > > One time I set up a png device and ran the plot and saved it: > > http://lark.cc.ukans.edu/~pauljohn/R/ExampleCode/gamma4.png > > Another time I forgot to turn on the device, ran the plot, then used > dev.copy(png, file="poissonCLT",width=500,height=1000) to get: > > http://lark.cc.ukans.edu/~pauljohn/R/ExampleCode/poissonCLT.png > > in the poissonCLT.png, to my eye the background is light green, while in > the gamma4.png, it is white. DO you see it too?Works well for me (R-1.4.1, WinNT4; your version / OS?). You didn't specify a background color with par(bg=...) before?> 3. In all of these examples, I have had trouble positioning text in > figures. Because I don't know what the plotted values will be until the > model is run, it is hard to write coordinates for text(x,y,""). I > frequently wish there were a way to say "top left part of graph",You get those coordinates with par("usr")> but the best i can come up with is to find the coordinates of the max or min > values of x and y and put the text there. > > I have that code in the bottom of this one: > > http://lark.cc.ukans.edu/~pauljohn/R/ExampleCode/template_poisson4.r > > After using Axum for years, this seems a bit odd to me, but I'm willing > to do it, if that is what you really intend us to do.Uwe Ligges -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
--- Paul Johnson <pauljohn at ku.edu> wrote:> 1. When I use paste to edit a title, it inserts spaces where I don't > want them. > > See the picture here: > > http://lark.cc.ukans.edu/~pauljohn/R/ExampleCode/gamma4.png > > and note that, after the equal signs and the number 1, there is a space > inserted whenever there is a comma separating text from variable. The > code in question is: > > http://lark.cc.ukans.edu/~pauljohn/R/ExampleCode/template_gamma4.r > > the line I use to set the title is: > > oneHist <- hist(oneGamma,main=paste("here is one sample from your > gamma(sh=",sh,",sc=",sc,")"))Use sep = "" in paste() (defaults to sep = " ").> 3. In all of these examples, I have had trouble positioning text in > figures. Because I don't know what the plotted values will be until the > model is run, it is hard to write coordinates for text(x,y,""). I > frequently wish there were a way to say "top left part of graph", but > the best i can come up with is to find the coordinates of the max or min > values of x and y and put the text there. > > I have that code in the bottom of this one: > > http://lark.cc.ukans.edu/~pauljohn/R/ExampleCode/template_poisson4.r > > > After using Axum for years, this seems a bit odd to me, but I'm willing > to do it, if that is what you really intend us to do.I'm not sure what exactly you're looking for, but have you tried working with par("usr") ? Deepayan __________________________________________________ Yahoo! Sports - Coverage of the 2002 Olympic Games -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Paul Johnson <pauljohn at ku.edu> wrote:> I have had trouble positioning text in figures. Because I don't know what > the plotted values will be until the model is run, it is hard to write > coordinates for text(x,y,""). I frequently wish there were a way to say "top > left part of graph"...As several people have replied, you need par("usr"). Here's a simple function that does it for you. You pass "absolute" coordinates xa and ya in the range [0,1], and it returns the user coordinates you need for "text", "legend", etc.: ------------------------------------------------------------------------------- g.coord <- function(xa, ya, u=par("usr")) { z <- list(x=u[1]+xa*(u[2]-u[1]), y=u[3]+ya*(u[4]-u[3])) if (par("xlog")) z$x <- 10^z$x; if (par("ylog")) z$y <- 10^z$y z } ------------------------------------------------------------------------------- To put text near the top left (but 2% in from the edges), type: R> text(g.coord(.02,.98), "Hello", adj=c(0,1)) One subtlety: text() somehow recognizes that its first argument is a list(x,y), and its second argument is therefore the "labels" to print. However, this recognition fails if you use plotmath. So this doesn't work: R> text(g.coord(.02, .98), quote(x==5), adj=c(0,1)) # Fails but the solution is simple: you just need to name the "labels" argument: R> text(g.coord(.02, .98), l=quote(x==5), adj=c(0,1)) # OK (Note that's the letter "l", short for "labels".) -- -- David Brahm (brahm at alum.mit.edu) -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._