[R] formula version of sunflowerplot() fails when axis labelspecified

Gerrit Eichner Gerrit.Eichner at math.uni-giessen.de
Thu Jun 28 16:39:57 CEST 2012


Thank you, Sina,
thank you, David,

I knew how to access the code of sunflowerplot.formula() and that 
sunflowerplot() does work in the default version, i.e., w/o formula (but 
your suggestions triggered my ambition ;-)).

Below is my -- slightly commented -- version (the search for which was 
inspired by Sina's approach) which results from studying the code of 
various other plotting functions with formula interface (e.g., 
boxplot.fomula(), stripchart.formula, and, in particular, plot.formula().)

  Hth and best regards  --  Gerrit

---------------------------------------------------------------------
Dr. Gerrit Eichner                   Mathematical Institute, Room 212
gerrit.eichner at math.uni-giessen.de   Justus-Liebig-University Giessen
Tel: +49-(0)641-99-32104          Arndtstr. 2, 35392 Giessen, Germany
Fax: +49-(0)641-99-32109        http://www.uni-giessen.de/cms/eichner
---------------------------------------------------------------------

sunflowerplot.formula <- function( formula, data = NULL,
                                    xlab = NULL, ylab = NULL, ...,
                                    subset, na.action = NULL) {
  if(missing(formula) || (length(formula) != 3L))
   stop("formula missing or incorrect")

  m <- match.call(expand.dots = FALSE)
  if (is.matrix(eval(m$data, parent.frame())))
   m$data <- as.data.frame(data)

  m$... <- NULL
  m$xlab <- m$ylab <- NULL   # New: Deleting xlab and ylab from m to
                             # avoid hindrance of the computation of
                             # the model frame below.
  m$na.action <- na.action

  require(stats, quietly = TRUE)
  m[[1L]] <- as.name("model.frame")
  mf <- eval(m, parent.frame())     # Here used to lie the problem.

  if (NCOL(mf) != 2L)
   stop("'formula' should specify exactly two variables")
  if (is.null(xlab))
   xlab <- names(mf)[2L]
  if (is.null(ylab))
    ylab <- names(mf)[1L]
  sunflowerplot(mf[[2L]], mf[[1L]],
                xlab = xlab, ylab = ylab, # New: To make sure that possibly
                                          # user defined labels are used.
                ...)
  }



More information about the R-help mailing list