Example in stat_summary documentation doesn't work

726 views
Skip to first unread message

Ben

unread,
Nov 15, 2010, 5:56:32 PM11/15/10
to ggplot2
Hi all,

I'm working through the examples on the stat_summary page (http://
had.co.nz/ggplot2/stat_summary.html) and halfway down the page, things
stop working (transcript below). Can someone tell me if I'm doing
something wrong, or does the documentation need to be updated? This is
using R 2.11.1 on a Mac, standard installation.

Thanks,
Ben

> library(ggplot2)
Loading required package: reshape
Loading required package: plyr
Loading required package: grid
Loading required package: proto
> c <- qplot(cyl, mpg, data=mtcars)

{... examples work until...}

> stat_sum_df <- function(fun, geom="crossbar", ...) {
+ stat_summary(fun=fun, colour="red", geom=geom, width=0.2, ...)
+ }

> c + stat_sum_df("mean_cl_boot")
Error in get("calculate_groups", env = .$stat, inherits = TRUE)(.
$stat, :
argument 4 matches multiple formal arguments

> # try using fun.y instead of fun, after googling problem
> stat_sum_df <- function(fun, geom="crossbar", ...) {
+ stat_summary(fun.y=fun, colour="red", geom=geom, width=0.2, ...)
+ }

> c + stat_sum_df("mean_cl_boot")
Error: geom_crossbar requires the following missing aesthetics: y,
ymin, ymax

romunov

unread,
Nov 15, 2010, 6:27:53 PM11/15/10
to Ben, ggplot2
Hey Ben,

everything checks out a-ok (Ubuntu 10.04). Looks like hamster may be in your circuits.

sessionInfo()
R version 2.12.0 (2010-10-15)
Platform: i486-pc-linux-gnu (32-bit)

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

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

other attached packages:
[1] Hmisc_3.8-3     survival_2.35-8 ggplot2_0.8.8   proto_0.3-8   
[5] reshape_0.8.3   plyr_1.2.1    

loaded via a namespace (and not attached):
[1] cluster_1.13.1  digest_0.4.2    lattice_0.19-13 tcltk_2.12.0  
[5] tools_2.12.0  


Cheers,
Roman




--
You received this message because you are subscribed to the ggplot2 mailing list.
Please provide a reproducible example: http://gist.github.com/270442

To post: email ggp...@googlegroups.com
To unsubscribe: email ggplot2+u...@googlegroups.com
More options: http://groups.google.com/group/ggplot2



--
In God we trust, all others bring data.

Brandon Hurr

unread,
Nov 16, 2010, 3:53:54 AM11/16/10
to romunov, Ben, ggplot2
I can confirm the sample code works on my machine too. 

> stat_sum_df <- function(fun, geom="crossbar", ...) { 
+    stat_summary(fun.data=fun, colour="red", geom=geom, width=0.2, ...) 
+  } 
> c + stat_sum_df("mean_cl_boot")
> sessionInfo()
R version 2.12.0 (2010-10-15)
Platform: i386-apple-darwin9.8.0/i386 (32-bit)

locale:
[1] en_US.UTF-8/en_US.UTF-8/C/C/en_US.UTF-8/en_US.UTF-8

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

other attached packages:
[1] Hmisc_3.8-3     survival_2.35-8 ggplot2_0.8.8   proto_0.3-8     reshape_0.8.3   plyr_1.2.1     

loaded via a namespace (and not attached):
[1] cluster_1.13.1  digest_0.4.2    lattice_0.19-13

Ben Bond-Lamberty

unread,
Nov 15, 2010, 8:20:36 PM11/15/10
to romunov, ggplot2
Thanks for checking, Roman.

I've just updated to a clean 2.12.0 installation, downloaded ggplot2
and its dependencies anew, and stlll get the error (see previous
message). So if anyone has any insight, or can test this on the same
platform I'm running, it would be much appreciated.

Regards,
Ben


R version 2.12.0 (2010-10-15)
Platform: x86_64-apple-darwin9.8.0/x86_64 (64-bit)

locale:
[1] en_US.UTF-8/en_US.UTF-8/C/C/en_US.UTF-8/en_US.UTF-8

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

datasets methods base

other attached packages:
[1] Hmisc_3.8-3 survival_2.35-8 ggplot2_0.8.8 proto_0.3-8

reshape_0.8.3
[6] plyr_1.2.1

loaded via a namespace (and not attached):

[1] cluster_1.13.1 lattice_0.19-13 tools_2.12.0

Mark Connolly

unread,
Nov 16, 2010, 6:09:44 AM11/16/10
to Ben Bond-Lamberty, romunov, ggplot2
stat_sum_df <- function(fun, geom="crossbar", ...) {
stat_summary(fun.data=fun, # fun.data, not fun

colour="red", geom=geom, width=0.2, ...)
}

Ben Bond-Lamberty

unread,
Nov 16, 2010, 6:49:28 AM11/16/10
to Mark Connolly, ggplot2
...and that works! Thanks, Mark.

So in summary, the example code doesn't work on (my) 64-bit R on Mac.
It does work on 32-bit Mac and Ubuntu. I'll check other 64-bit
versions to see if it's reproducible, or if something is wonky at my
end.

Ben

Hadley Wickham

unread,
Nov 16, 2010, 9:05:53 AM11/16/10
to Ben Bond-Lamberty, Mark Connolly, ggplot2
The simple explanation is that the code on the website is out of date,
but the code in the example is not, and you probably have different
versions of ggplot2 installed on your different computers.

Hadley

> --
> You received this message because you are subscribed to the ggplot2 mailing list.
> Please provide a reproducible example: http://gist.github.com/270442
>
> To post: email ggp...@googlegroups.com
> To unsubscribe: email ggplot2+u...@googlegroups.com
> More options: http://groups.google.com/group/ggplot2
>

--
Assistant Professor / Dobelman Family Junior Chair
Department of Statistics / Rice University
http://had.co.nz/

Reply all
Reply to author
Forward
0 new messages