I'm graphing a series of boxplots of grouped data inside a function that passes the data.frame, the names vector, and a title vector. Because both the data subset changes with each successive pass through the function, occasionally the names vector turns up with only one group to plot. This is an expected result. However, when the names argument in boxplot has only a single name, it doesn't put in on the boxplot. (Actually, this is true whether the names argument is present or not. If the call to boxplot is in formula form (e.g. variable ~ group), the plot doesn't name the group if there is only one group.) Here is a small example that produces the desired boxplots and labels them horizontally with "GO", "HO", "PA", "PO" as I want: attach(hominoid) #contains raw data groups<-c("GO", "HO", "PA", "PO") boxplot(latsupri~genus, main = "latsupri", horizontal=T, las=1, names=groups) This example produces the needed boxplot, but fails to put the "GO" anywhere on the plot attach(hominoid) groups<-"GO" # groups<-c("GO") doesn't do any better boxplot(latsupri~genus, main = "latsupri", horizontal=T, las=1, names=groups) So, since I've got lots of these to do and some of these happen to end up with single groups (and hence no name on the boxplot), how do I get boxplot to put the name of the single group in the same place it would be if there were more than one group? Thanks. ====================Dr. Marc R. Feldesman Professor and Chairman Anthropology Department Portland State University 1721 SW Broadway Portland, Oregon 97201 email: feldesmanm at pdx.edu phone: 503-725-3081 fax: 503-725-3905 http://web.pdx.edu/~h1mf PGP Key Available On Request ===================== "Anyway, no drug, not even alcohol, causes the fundamental ills of society. If we're looking for the source of our troubles, we shouldn't test people for drugs, we should test them for stupidity, ignorance, greed and love of power." P.J. O'Rourke Powered by Optiplochoerus and Windows 2000 (scary isn't it?) -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
On Fri, 27 Jul 2001, Marc Feldesman wrote:> I'm graphing a series of boxplots of grouped data inside a function that > passes the data.frame, the names vector, and a title vector. > > Because both the data subset changes with each successive pass through the > function, occasionally the names vector turns up with only one group to > plot. This is an expected result. However, when the names argument in > boxplot has only a single name, it doesn't put in on the > boxplot. (Actually, this is true whether the names argument is present or > not. If the call to boxplot is in formula form (e.g. variable ~ group), > the plot doesn't name the group if there is only one group.)Yes. In order to get around this you need to modify the bxp() function that does the actual plotting. My recommended change is to add a show.names argument: function (z, notch = FALSE, width = NULL, varwidth = FALSE, notch.frac 0.5, boxwex = 0.8, border = par("fg"), col = NULL, log = "", pars NULL, frame.plot = axes, horizontal = FALSE, add = FALSE, at = NULL, show.names=NULL, ...) and then near the end of the function replace the if(axes) conditional with if (axes) { ax.pars <- pars[names(pars) %in% c("xaxt", "yaxt", "las")] if(is.null(show.names)) show.names<-(n>1) if (show.names) do.call("axis", c(list(side = 1 + horizontal, at = at, labels = z$names), ax.pars)) do.call("axis", c(list(side = 2 - horizontal), ax.pars)) } Now the standard behaviour is the same but you can override it with temp<-boxplot(y~g,plot=FALSE) bxp(temp,show.names=TRUE) or if you have multiple groups but don't want names for some strange reason bxp(temp,show.names=FALSE) -thomas Thomas Lumley Asst. Professor, Biostatistics tlumley at u.washington.edu University of Washington, Seattle -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
At 01:39 PM 7/27/01, Thomas Lumley wrote: >On Fri, 27 Jul 2001, Marc Feldesman wrote: > >> I'm graphing a series of boxplots of grouped data inside a function that >> passes the data.frame, the names vector, and a title vector. >> >> Because both the data subset changes with each successive pass through the >> function, occasionally the names vector turns up with only one group to >> plot. This is an expected result. However, when the names argument in >> boxplot has only a single name, it doesn't put in on the >> boxplot. (Actually, this is true whether the names argument is present or >> not. If the call to boxplot is in formula form (e.g. variable ~ group), >> the plot doesn't name the group if there is only one group.) > >Yes. In order to get around this you need to modify the bxp() function >that does the actual plotting. > > >My recommended change is to add a show.names argument: > > function (z, notch = FALSE, width = NULL, varwidth = FALSE, notch.frac > 0.5, boxwex = 0.8, border = par("fg"), col = NULL, log = "", pars > NULL, frame.plot = axes, horizontal = FALSE, add = FALSE, at = NULL, > show.names=NULL, ...) > >and then near the end of the function replace the if(axes) conditional >with > > if (axes) { > ax.pars <- pars[names(pars) %in% c("xaxt", "yaxt", "las")] > if(is.null(show.names)) show.names<-(n>1) > if (show.names) > do.call("axis", c(list(side = 1 + horizontal, at = at, > labels = z$names), ax.pars)) > do.call("axis", c(list(side = 2 - horizontal), ax.pars)) > } > > >Now the standard behaviour is the same but you can override it with > > temp<-boxplot(y~g,plot=FALSE) > bxp(temp,show.names=TRUE) > >or if you have multiple groups but don't want names for some strange >reason > bxp(temp,show.names=FALSE) > This is a handy solution that works well as long as one remembers to put parameters usually included in the boxplot() call in the call to bxp(). Any chance of making this a part of the next release of R? It doesn't seem like it should/would break existing code. -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._