I found and example for the %+% operator in ggplot2 to use a different data frame for the same plot. Examples are available here.
When I try this, I get an error message:
df <- data.frame(x=rnorm(1000), y=rnorm(1000))
p <- ggplot(df, aes(x,y)) + geom_point()
p
p %+% df[1:100,]
Error in p %+% df[1:100, ] : x must be either a vector or a matrix
Did I misunderstood the example on the website?
sessionInfo()
sessionInfo()
R version 3.2.0 (2015-04-16)
Platform: x86_64-apple-darwin13.4.0 (64-bit)
Running under: OS X 10.9.5 (Mavericks)
locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
attached base packages:
[1] grid stats graphics grDevices utils datasets methods base
other attached packages:
[1] cfpscripts_0.4.0 seqinr_3.1-3 ade4_1.7-2 gridExtra_0.9.1 psych_1.5.4 reshape2_1.4.1 plyr_1.8.3 knitr_1.10.5 rMQanalysis_0.2.0 ggplot2_1.0.1 testthat_0.10.0
[12] devtools_1.8.0
loaded via a namespace (and not attached):
[1] Rcpp_0.12.0 git2r_0.10.1 tools_3.2.0 digest_0.6.8 memoise_0.2.1 gtable_0.1.2 lattice_0.20-31 curl_0.8 parallel_3.2.0
[10] proto_0.3-10 stringr_1.0.0 imbproteomicsr_0.1.7 xml2_0.1.1 rversions_1.0.1 data.table_1.9.4 sp_1.1-1 magrittr_1.5 scales_0.2.5
[19] cfppdfs_0.3.4 MASS_7.3-40 mnormt_1.5-3 splitstackshape_1.4.2 logspline_2.1.8 colorspace_1.2-6 labeling_0.3 stringi_0.5-5 munsell_0.4.2
[28] chron_2.3-45 crayon_1.3.0 zoo_1.7-12
ggplot2_1.0.1. Try updating yourggplot2package. Also you can see if?"%+%"finds a ggplot2 functionpsychpackage overwrites the%+%function. Is there a way to call theggplot2version explizit?ggplot2::%+%did not work.psychbefore you loadggplot2? or put single-back-quotes around%+%in `ggplot2:``%+%```ggplot2:notation since it seems to be more stable in case of errors but I can not get it to work. R always complains aboutunexpected symbol in "p ggplot2". p is my graph and I try ggplot2::'%+%' but the ' are single back ticks which would now highlight my command. I tried also with only one colon, double back ticks and a lot of different combinations but always the same error.