I'm using plot to make a simple plot but I want to control where the tick marks go on bot axes. The graphical parameters xaxp and yaxp seem to be ignored by the plot function so I tried setting them using op <- par(no.readonly=T) par(xaxp=c(-2.4,-2.2,5), yaxp=c(-2500,10000,6)) plot(...) par(op) but they are still ignored. Next I tried to use the axis function as follows op <- par(no.readonly=T) par(xaxt="n", yaxt="n") plot(...) axis(1,seq(-2.4,-2.2,length=5)) axis(2,seq(-2500,10000,length=6), cex.axis=0.9) par(op) but no axis labels are plotted. Moving par(op) before the calls to axis causes the first call to axis to extend the x-axis to the edge of the screen and the second call results in a 0 being placed at the bottom of the y-axis. Is this a bug or is it just that it's Friday afternoon? In any case can someone please help me out here. I'm using the following verison of R platform sparc-sun-solaris2.6 arch sparc os solaris2.6 system sparc, solaris2.6 status major 1 minor 0.0 year 2000 month February day 29 language R Angelo -- **************************************************** ** Angelo J. Canty ** ** Dept of Mathematics and Statistics ** ** Concordia University ** ** Montreal, Quebec. ** ** ** ** Tel : +1-514-848-3244 ** ** Fax : +1-514-848-4511 ** ** Email : canty at discrete.concordia.ca ** **************************************************** -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Well, my last attempt to answer a question about plot() parameters was wrong (sorry Dr. Ripley), but I'll try again. I'm not sure, but I would hazard a guess that your problem is that you haven't specified your x- and y-limits and that your data don't cover the range of the axis ranges you want. What are the x- and y-ranges of your data? I would try something along these lines: plot(...,xlim=c(-2.4,-2.2),ylim=c(-2500,10000),axes=FALSE) axis(1,seq(-2.4,-2.2,length=5) axis(2,seq(-2500,10000,length=6),cex.axis=0.9) hope that helps On Fri, 2 Jun 2000, Angelo Canty wrote:> I'm using plot to make a simple plot but I want to control where > the tick marks go on bot axes. The graphical parameters xaxp and > yaxp seem to be ignored by the plot function so I tried setting them > using > op <- par(no.readonly=T) > par(xaxp=c(-2.4,-2.2,5), yaxp=c(-2500,10000,6)) > plot(...) > par(op) > but they are still ignored. > > Next I tried to use the axis function as follows > op <- par(no.readonly=T) > par(xaxt="n", yaxt="n") > plot(...) > axis(1,seq(-2.4,-2.2,length=5)) > axis(2,seq(-2500,10000,length=6), cex.axis=0.9) > par(op) > but no axis labels are plotted. > > Moving par(op) before the calls to axis causes the first call to axis to > extend the x-axis to the edge of the screen and the second call results > in a 0 being placed at the bottom of the y-axis. > > Is this a bug or is it just that it's Friday afternoon? In any case > can someone please help me out here. > > I'm using the following verison of R > platform sparc-sun-solaris2.6 > arch sparc > os solaris2.6 > system sparc, solaris2.6 > status > major 1 > minor 0.0 > year 2000 > month February > day 29 > language R > > Angelo > > >-- Ben Bolker bolker at zoo.ufl.edu Zoology Department, University of Florida http://www.zoo.ufl.edu/bolker 318 Carr Hall/Box 118525 tel: (352) 392-5697 Gainesville, FL 32611-8525 fax: (352) 392-3704 -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Angelo Canty <canty at discrete.Concordia.CA> writes:> I'm using plot to make a simple plot but I want to control where > the tick marks go on bot axes. The graphical parameters xaxp and > yaxp seem to be ignored by the plot function so I tried setting them > using > op <- par(no.readonly=T) > par(xaxp=c(-2.4,-2.2,5), yaxp=c(-2500,10000,6)) > plot(...) > par(op) > but they are still ignored. > > Next I tried to use the axis function as follows > op <- par(no.readonly=T) > par(xaxt="n", yaxt="n") > plot(...) > axis(1,seq(-2.4,-2.2,length=5)) > axis(2,seq(-2500,10000,length=6), cex.axis=0.9) > par(op) > but no axis labels are plotted. > > Moving par(op) before the calls to axis causes the first call to axis to > extend the x-axis to the edge of the screen and the second call results > in a 0 being placed at the bottom of the y-axis. > > Is this a bug or is it just that it's Friday afternoon? In any case > can someone please help me out here. > > I'm using the following verison of R > platform sparc-sun-solaris2.6 > arch sparc > os solaris2.6 > system sparc, solaris2.6 > status > major 1 > minor 0.0Some bugs relating to axes were fixed in 1.0.1, but your first example still won't work. This looks suspiciously like a bug - to force axis to actually use xaxp/yaxp one has to pass at=NULL explicitly and it doesn't work to pass them to plot or set them beforehand with par because they're being recalculated along the way. (I don't think the latter is a bug -- to use "current settings" would imply inheriting axes from the previous plot which you likely do not want! However, passing them explicitly to plot ought to work.) Your 2nd example is flawed: Once you set par(xaxt="n"), axis(1,...) will plot nothing, whatever arguments you give it. What does work is stuff like plot(1,xaxt="n") axis(1,at=seq(from=0.7,to=1.3,length=5)) although I suspect that the bug in 1.0.0 prevents this from working, and you have to work around it with par(xaxt="n");plot(1);par(xaxt="s") axis(1,at=seq(from=0.7,to=1.3,length=5)) The version that I normally use (because I can't remember all those par() settings...) goes along the lines of plot(1, axes=F) axis(1,at=seq(from=0.7,to=1.3,length=5)) axis(2) box() -- O__ ---- Peter Dalgaard Blegdamsvej 3 c/ /'_ --- Dept. of Biostatistics 2200 Cph. N (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk) FAX: (+45) 35327907 -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Dear All, I am writing a function to analyze simulated data. For each subset of data (those with the same simulation counter), I have to fit a linear model and output the coefficients and the F's from drop1 (marginal F tests). I have tried three approaches: using lapply, using a for loop, and looping over blocks, where within each block I use lapply (following the suggestion in "S programming", pp. 156 and 174). The later is often the fastest method (execution time can be less than half of the other methods). I am wondering: a) why exactly is that the case? (Is it related to the "split" in lapply or the "matrix(unlist(etc))" in my function) b) is there some rule of thumb to choose the size of the block over which to use lapply? Thanks, Ramon P.S. For completeness, I include below the core of the function I am using; comments most welcome. lmx.0 <- function(formula,data,max.num=0,lapply.size=100){ # looping over lapply # remeber that sim.counter starts at 0 if(max.num) data<-data[data$sim.counter<max.num+1,] else max.num<-max(data$sim.counter) names.vars<-drop.scope(formula) terms.in.model<-names(lm(formula=formula,data=data,subset=data$sim.counter==0)[[1]]) # there must be a simpler way... loop.counter<-(max.num+1)%/%lapply.size rest.of.data<-(max.num+1)%%lapply.size tmp<-matrix(nrow=max.num+1,ncol=length(names.vars)+length(terms.in.model)) i<-0 if (loop.counter) { #only enter in the loop if needed for(i in 1:loop.counter){ datai<-data[data$sim.counter<=((i*lapply.size)-1) & data$sim.counter>=((i-1)*lapply.size),] # obtain output of interest ---fm[[1]],my.drop(fm)--- by applying that function # over the subset of data within loop; as result is list, unlist and turn into a matrix # it is a little bit hard to read, but I am trying to minimize creating large # intermediate objects. tmp[(((i-1)*lapply.size)+1):(i*lapply.size),]<-matrix(unlist(lapply(split(datai,datai$sim.counter), function(datos,formula){ fm<-lm(formula=formula,data=datos); c(fm[[1]],my.drop(fm))}, formula=formula)), nrow=lapply.size,byrow=T) }} # here we deal with the other cases datai<-data[data$sim.counter>=(loop.counter*lapply.size),] tmp[(((i*lapply.size)+1):(max.num+1)),] <- matrix(unlist(lapply(split(datai,datai$sim.counter), function(datos,formula){fm<-lm(formula=formula,data=datos); c(fm[[1]],my.drop(fm))}, formula=formula)), nrow=rest.of.data,byrow=T) tmp } my.drop<- function (object) { # This is from drop1 (by BDR) after eliminating things I didn't need; # this function is severely crippled, so use only here # components are NOT named x <- model.matrix(object) iswt <- !is.null(wt <- object$weights) n <- nrow(x) asgn <- attr(x, "assign") tl <- attr(object$terms, "term.labels") scope <- drop.scope(object) ndrop <- match(scope, tl) ns <- length(scope) rdf <- object$df.resid chisq <- deviance.lm(object) dfs <- numeric(ns) RSS <- numeric(ns) y <- object$residuals + predict(object) rank <- object$rank for (i in 1:ns) { ii <- seq(along = asgn)[asgn == ndrop[i]] jj <- setdiff(seq(ncol(x)), ii) z <- if (iswt) lm.wfit(x[, jj, drop = FALSE], y, wt) else lm.fit(x[, jj, drop = FALSE], y) dfs[i] <- z$rank RSS[i] <- deviance.lm(z) } dfs <- c(object$rank, dfs) RSS <- c(chisq, RSS) dfs <- (dfs[1] - dfs)[-1] rdf <- object$df.resid dev<-RSS[-1]-RSS[1] rms<-RSS[1]/rdf Fs<-(dev/dfs)/rms Fs } -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._