new ggplot2 and custom boxplot code

 

Questions


I have been using a ammended version of Kohske’s code from this post To which I add an additional argument for outlier.alpha. However, with the new ggplot2 release, its giving me an error. The first error:

Error in eval.with.vis(expr, envir, enclos) : 
  could not find function "proto"

Is due to the name spacing of the new ggplot and is fixed with library(proto). Then the error becomes:

Error in proto(GeomBoxplot, { : object 'GeomBoxplot' not found

That can be fixed by using ggplot:::GeomBoxplot to access the unexported function. However, then the final assignment:

geom_boxplot_jitter_outlier <- GeomBoxplotJitterOutlier$build_accessor()

errors with:

Error in get(x, envir = this, inherits = inh) : 
  object 'build_accessor' not found

Now, I’m at a loss!! The custom geom code is below as is my sessionInfo().

GeomBoxplotJitterOutlier <- proto(GeomBoxplot, {
   draw <- function (., data, ..., outlier.colour = "black", outlier.shape = 16, 
    outlier.size = 2, outlier.jitter=0,outlier.alpha=1) {
# copy the body of function 'draw' above and paste here.
defaults <- with(data, data.frame(x = x, xmin = xmin, xmax = xmax, 
        colour = colour, size = size, linetype = 1, group = 1, 
        alpha = 1, fill = alpha(fill, alpha), stringsAsFactors = FALSE))
    defaults2 <- defaults[c(1, 1), ]
        if (!is.null(data$outliers) && length(data$outliers[[1]] >= 
        1)) {
            pp<-position_jitter(width=outlier.jitter,height=0)
            p<-pp$adjust(data.frame(x=data$x[rep(1, length(data$outliers[[1]]))], y=data$outliers[[1]]),.scale)
        outliers_grob <- GeomPoint$draw(data.frame(x=p$x, y = p$y, colour = I(outlier.colour), 
            shape = outlier.shape, alpha = outlier.alpha, size = outlier.size, 
            fill = NA), ...)
    }
    else {
        outliers_grob <- NULL
    }
    with(data, ggname(.$my_name(), grobTree(outliers_grob, GeomPath$draw(data.frame(y = c(upper, 
        ymax), defaults2), ...), GeomPath$draw(data.frame(y = c(lower, 
        ymin), defaults2), ...), GeomRect$draw(data.frame(ymax = upper, 
        ymin = lower, defaults), ...), GeomRect$draw(data.frame(ymax = middle, 
        ymin = middle, defaults), ...))))

}

  objname <- "boxplot_jitter_outlier"
  desc <- "Box and whiskers plot with jittered outlier"
  guide_geom <- function(.) "boxplot_jitter_outlier"

})

geom_boxplot_jitter_outlier <- GeomBoxplotJitterOutlier$build_accessor()



> sessionInfo()
R version 2.14.2 (2012-02-29)
Platform: x86_64-pc-linux-gnu (64-bit)

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C               LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8    
 [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8    LC_PAPER=C                 LC_NAME=C                 
 [9] LC_ADDRESS=C               LC_TELEPHONE=C             LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       

attached base packages:
[1] graphics  grDevices utils     datasets  stats     grid      methods   base     

other attached packages:
 [1] proto_0.3-9.2     circular_0.4-3    boot_1.3-4        mgcv_1.7-13       stringr_0.6       RPostgreSQL_0.3-2 biglm_0.8        
 [8] DBI_0.2-5         doMC_1.2.3        multicore_0.1-7   foreach_1.3.2     codetools_0.2-8   iterators_1.0.5   splancs_2.01-29  
[15] sp_0.9-91         ellipse_0.3-5     MASS_7.3-16       ggplot2_0.9.0     reshape2_1.2.1    plyr_1.7.1       

loaded via a namespace (and not attached):
 [1] colorspace_1.1-1   compiler_2.14.2    dichromat_1.2-4    digest_0.5.1       lattice_0.20-0     Matrix_1.0-4      
 [7] memoise_0.1        munsell_0.3        nlme_3.1-103       RColorBrewer_1.0-5 scales_0.2.0      

 

 

————————————————-

Answer

ggplot2,r

[], []

Facebook Comments

Post a comment