ggplot2: ..count.. not working with stat_bin_hex anymore - r

Some months ago I was able to produce the following plot without errors:
library(ggplot2)
library(hexbin)
x <- rnorm(100)
y <- rnorm(100, mean=2)
ggplot(data = data.frame(x,y)) + stat_bin_hex(aes(x=x, y=y, alpha=..count..), fill="#ED1A3A", bins=10)
Now this does not work anymore and I get the error
Error in eval(expr, envir, enclos) : Object 'count' not found
Any help how I get this working again and explanation why its not working anymore?
Thanks!
EDIT 1: My session info in any case:
R version 3.2.3 (2015-12-10)
Platform: x86_64-apple-darwin14.5.0 (64-bit)
Running under: OS X 10.11.5 (El Capitan)
locale:
[1] de_DE.UTF-8/de_DE.UTF-8/de_DE.UTF-8/C/de_DE.UTF-8/de_DE.UTF-8
attached base packages:
[1] grid stats graphics grDevices utils datasets methods base
other attached packages:
[1] hexbin_1.27.1 knitcitations_1.0.7 dplyr_0.4.3 XLConnect_0.2-11 XLConnectJars_0.2-9
[6] data.table_1.9.6 scales_0.4.0 ggplot2_2.1.0 gridExtra_2.2.1 extrafont_0.17
[11] np_0.60-2
loaded via a namespace (and not attached):
[1] Rcpp_0.12.5 plyr_1.8.3 bitops_1.0-6 tools_3.2.3 boot_1.3-18
[6] digest_0.6.9 lattice_0.20-33 lubridate_1.5.6 gtable_0.2.0 bibtex_0.4.0
[11] DBI_0.4-1 yaml_2.1.13 parallel_3.2.3 rJava_0.9-8 Rttf2pt1_1.3.4
[16] knitr_1.13 stringr_1.0.0 httr_1.1.0 RefManageR_0.10.13 R6_2.1.2
[21] XML_3.98-1.4 rmarkdown_0.9.6 RJSONIO_1.3-0 extrafontdb_1.0 magrittr_1.5
[26] htmltools_0.3.5 assertthat_0.1 cubature_1.1-2 colorspace_1.2-6 labeling_0.3
[31] stringi_1.0-1 RCurl_1.95-4.8 lazyeval_0.1.10 munsell_0.4.3 chron_2.3-47
EDIT 2: Interestingly it still works with stat_bin_2d.

This seems to be related to the open issue
geom_hex no longer recognizes ..density.. in 2.1.0 #1608
(Github)
that seems to have to fix, yet.
Update 2016-09-18: Check out this answer on Stackoverflow.

Related

POSIXts error when quit Rstudio

When I tried to close Rstudio in Mac I get the following error:
Error in as.POSIXlt(x, tz = tz(x)) :
argument "x" is missing, with no default
Have not tried to reisntall Rstudio as i am hoping can fix the issue.
this are the packages loaded in session:
library(readr)
library(dplyr)
library(lubridate)
library(ggplot2)
library(scales)
These are the objects in the global env:
> ls()
[1] "csv" "csv2" "csv3" "p"
>
Have tried base::q() and base::quit() and get the same error.
sessionInfo()
R version 3.4.0 (2017-04-21)
Platform: x86_64-apple-darwin15.6.0 (64-bit)
Running under: macOS Sierra 10.12.6
Matrix products: default
BLAS: /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/3.4/Resources/lib/libRlapack.dylib
locale:
[1] en_GB.UTF-8/en_GB.UTF-8/en_GB.UTF-8/C/en_GB.UTF-8/en_GB.UTF-8
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] shiny_1.0.3 scales_0.4.1 ggplot2_2.2.1 bindrcpp_0.2 dplyr_0.7.1 lubridate_1.6.0 readr_1.1.1
loaded via a namespace (and not attached):
[1] Rcpp_0.12.11 compiler_3.4.0 colourpicker_0.3 plyr_1.8.4 bindr_0.1 shinyjs_0.9.1
[7] tools_3.4.0 digest_0.6.12 jsonlite_1.5 tibble_1.3.3 gtable_0.2.0 pkgconfig_2.0.1
[13] rlang_0.1.1 rstudioapi_0.6 curl_2.7 stringr_1.2.0 knitr_1.16 htmlwidgets_0.8
[19] hms_0.3 grid_3.4.0 glue_1.1.1 R6_2.2.2 magrittr_1.5 htmltools_0.3.6
[25] assertthat_0.2.0 mime_0.5 colorspace_1.3-2 xtable_1.8-2 httpuv_1.3.3 labeling_0.3
[31] V8_1.5 stringi_1.1.5 miniUI_0.1.1 lazyeval_0.2.0 munsell_0.4.3
This could be because lubridate expects input but base::date() does not need it. Removing lubridate might solve the issue, or using base::date() instead. See this thread for a discussion on this issue.
I hope this helps!

Can't access existing MonetDB with dplyr

I created a MonetDBLite database yesterday, populated it, and was accessing it with dplyr, however this morning I don't seem able to use dplyr.
Here's my connection:
statcast_db <- MonetDBLite::src_monetdblite("/Users/williampetti/statcast_database/statcast_db_Monet", create = FALSE)
And here's a simple query for the statcast_17 table:
statcast_db %>%
tbl("statcast_17") %>%
select(game_date) %>%
distinct() %>%
collect() %>%
tail(n = 1)
Yesterday, this worked fine. This morning, I get this error:
Error in UseMethod("db_query_fields") :
no applicable method for 'db_query_fields' applied to an object of class "MonetDBEmbeddedConnection"
If I use a simple dbGetQuery call, however, it works fine:
> dbGetQuery(statcast_db$con, "SELECT game_date FROM statcast_17 ORDER BY game_date DESC LIMIT 1")
game_date
1 2017-04-29
Here's my session info:
> sessionInfo()
R version 3.3.1 (2016-06-21)
Platform: x86_64-apple-darwin13.4.0 (64-bit)
Running under: OS X 10.11.6 (El Capitan)
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] stats graphics grDevices utils datasets methods base
other attached packages:
[1] xml2_1.1.1 baseballr_0.3.1 RSQLite_1.0.0 pacman_0.4.1
[5] dplyr_0.5.0 purrr_0.2.2 readr_1.0.0 tidyr_0.6.0
[9] tibble_1.2 ggplot2_2.2.1 tidyverse_1.0.0 magrittr_1.5
[13] MonetDBLite_0.3.1 RMySQL_0.10.9 DBI_0.5-1
loaded via a namespace (and not attached):
[1] splines_3.3.1 lattice_0.20-33 colorspace_1.2-6
[4] htmltools_0.3.5 mgcv_1.8-12 chron_2.3-47
[7] XML_3.98-1.6 survival_2.40-1 hexbin_1.27.1
[10] foreign_0.8-66 RColorBrewer_1.1-2 plyr_1.8.4
[13] stringr_1.2.0 munsell_0.4.3 gtable_0.2.0
[16] rvest_0.3.2 XML2R_0.0.6 codetools_0.2-14
[19] latticeExtra_0.6-28 knitr_1.14 reldist_1.6-6
[22] htmlTable_1.7 Rcpp_0.12.9 acepack_1.4.1
[25] scales_0.4.1 pitchRx_1.8.2 Hmisc_4.0-0
[28] gridExtra_2.2.1 digest_0.6.11 stringi_1.1.3
[31] grid_3.3.1 tools_3.3.1 bitops_1.0-6
[34] lazyeval_0.2.0 RCurl_1.95-4.8 Formula_1.2-1
[37] cluster_2.0.4 MASS_7.3-45 Matrix_1.2-6
[40] data.table_1.9.6 lubridate_1.6.0 httr_1.2.1
[43] assertthat_0.1 R6_2.1.3 rpart_4.1-10
[46] nnet_7.3-12 nlme_3.1-128
I just replied to a similar question this morning after figuring out that the order in which you load MonetDBLite matters. I came across this question trying to figure out why it does matter. I was having the same type of Error in UseMethod problems as BillPetti. Making sure MonetDBLite loads after dplyr and dbplyr has resolved the issue for me. Here's the link to that other answer:
https://stackoverflow.com/a/53307673/3705612

Function not found, though package installed an attached

im tryring to run dcc.est from the ccgarch-package.
Even though I installed the package and attached it with library(ccgarch), I get the following error:
library(ccgarch)
dcc <- dcc.est(dvar, param)
Error: could not find function "dcc.est"
I also tried the following:
dcc <- ccgarch::dcc.est(dvar, param)
Error: object 'dcc.est' is not exported by 'namespace:ccgarch'
Accordingly to the vignette of ccgarch version 0.2.3 (https://cran.r-project.org/web/packages/ccgarch/ccgarch.pdf) , dcc.est is part of the package. What am I doing wrong?
See my sessionInfobelow:
> sessionInfo()
R version 3.3.2 (2016-10-31)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows >= 8 x64 (build 9200)
locale:
[1] LC_COLLATE=German_Germany.1252 LC_CTYPE=German_Germany.1252 LC_MONETARY=German_Germany.1252
[4] LC_NUMERIC=C LC_TIME=German_Germany.1252
attached base packages:
[1] parallel stats graphics grDevices utils datasets methods base
other attached packages:
[1] pracma_1.9.5 kerdiest_1.2 evir_1.7-3 chron_2.3-48 date_1.2-35
[6] fGarch_3010.82.1 fBasics_3011.87 timeSeries_3022.101.2 timeDate_3012.100 rugarch_1.3-6
[11] tsDyn_0.9-44 ccgarch_0.2.3 gdata_2.17.0 gtools_3.5.0 tidyr_0.6.0
[16] dplyr_0.5.0
loaded via a namespace (and not attached):
[1] rgl_0.96.0 Rcpp_0.12.8 mvtnorm_1.0-5 lattice_0.20-34
[5] zoo_1.7-14 assertthat_0.1 digest_0.6.10 lmtest_0.9-34
[9] foreach_1.4.3 mime_0.5 truncnorm_1.0-7 R6_2.2.0
[13] plyr_1.8.4 tseriesChaos_0.1-13 ggplot2_2.2.0 lazyeval_0.2.0
[17] misc3d_0.8-4 fracdiff_1.4-2 nloptr_1.0.4 SkewHyperbolic_0.3-2
[21] Matrix_1.2-7.1 htmlwidgets_0.8 munsell_0.4.3 shiny_0.14.2
[25] numDeriv_2016.8-1 httpuv_1.3.3 DistributionUtils_0.5-1 mnormt_1.5-5
[29] forecast_7.3 urca_1.3-0 mgcv_1.8-15 htmltools_0.3.5
[33] vars_1.5-2 nnet_7.3-12 Rsolnp_1.16 multicool_0.1-10
[37] expm_0.999-0 tibble_1.2 quadprog_1.5-5 codetools_0.2-15
[41] MASS_7.3-45 GeneralizedHyperbolic_0.8-1 grid_3.3.2 nlme_3.1-128
[45] jsonlite_1.1 xtable_1.8-2 gtable_0.2.0 DBI_0.5-1
[49] magrittr_1.5 scales_0.4.1 KernSmooth_2.23-15 tseries_0.10-36
[53] xts_0.9-7 sandwich_2.3-4 spd_2.0-1 iterators_1.0.8
[57] tools_3.3.2 ks_1.10.4 colorspace_1.3-2 knitr_1.15.1
If you look at the NAMESPACE you see that dcc.est is commented out (it may have be replaced by dcc.estimation - just a guess, I've never used the package?).
This means it is not exported by the package, but it's still there, only as an internal function. You can access internal functions by using 3 colons
ccgarch:::dcc.est
As it's in the documentation I think somewhere along the line of updates and releases someone forgot to remove it properly, or un-comment it again in the export list.

plots not being printed in for loop when rendering PDF (since ggplot2 update)

I am attempting to render a PDF in which plots are outputted in a loop. The code I'm using previously worked as expected but now only the first plot in the loop is being printed in the pdf. The problem may be linked to the ggplot2 update (although I am not sure).
Below I have provided a reproducible example (as my rmarkdown file is far too long) which performs with the same error - printing only the first plot in the loop.
I may be missing something completely obvious of course! Any help greatly appreciated.
---
title: "Check"
output: pdf_document
---
```{r, results='asis'}
library(ggplot2)
Values = names(mtcars)[1:4]
mtcars$gear <- as.factor(mtcars$gear)
for(v in Values){
print(ggplot(mtcars, aes(x=carb, y = v, shape=gear)) + geom_point())
}
```
> sessionInfo()
R version 3.2.3 (2015-12-10)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 7 x64 (build 7601) Service Pack 1
locale:
[1] LC_COLLATE=English_Ireland.1252 LC_CTYPE=English_Ireland.1252 LC_MONETARY=English_Ireland.1252 LC_NUMERIC=C
[5] LC_TIME=English_Ireland.1252
attached base packages:
[1] grid stats graphics grDevices utils datasets methods base
other attached packages:
[1] HH_3.1-24 gridExtra_2.0.0 multcomp_1.4-1 TH.data_1.0-6 survival_2.38-3 mvtnorm_1.0-3 latticeExtra_0.6-26
[8] RColorBrewer_1.1-2 lattice_0.20-33 stringr_1.0.0 pander_0.6.0 xtable_1.8-0 ggplot2_2.0.0 rmarkdown_0.9.2
[15] markdown_0.7.7 knitr_1.12
loaded via a namespace (and not attached):
[1] zoo_1.7-12 reshape2_1.4.1 splines_3.2.3 colorspace_1.2-6 htmltools_0.3 yaml_2.1.13 gmp_0.5-12 foreign_0.8-66
[9] Rmpfr_0.6-0 plyr_1.8.3 munsell_0.4.2 gtable_0.1.2 leaps_2.9 codetools_0.2-14 evaluate_0.8 labeling_0.3
[17] httpuv_1.3.3 lmtest_0.9-34 vcd_1.4-1 proto_0.3-10 Rcpp_0.12.0 acepack_1.3-3.3 scales_0.3.0 formatR_1.2.1
[25] Hmisc_3.16-0 abind_1.4-3 mime_0.4 digest_0.6.9 stringi_1.0-1 shiny_0.13.0 tools_3.2.3 sandwich_2.3-3
[33] magrittr_1.5 Formula_1.2-1 cluster_2.0.3 MASS_7.3-45 R6_2.1.0 rpart_4.1-10 nnet_7.3-11 R version 3.2.3 (2015-12-10)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 7 x64 (build 7601) Service Pack 1
locale:
[1] LC_COLLATE=English_Ireland.1252 LC_CTYPE=English_Ireland.1252 LC_MONETARY=English_Ireland.1252 LC_NUMERIC=C
[5] LC_TIME=English_Ireland.1252
attached base packages:
[1] grid stats graphics grDevices utils datasets methods base
other attached packages:
[1] HH_3.1-24 gridExtra_2.0.0 multcomp_1.4-1 TH.data_1.0-6 survival_2.38-3 mvtnorm_1.0-3 latticeExtra_0.6-26
[8] RColorBrewer_1.1-2 lattice_0.20-33 stringr_1.0.0 pander_0.6.0 xtable_1.8-0 ggplot2_2.0.0 rmarkdown_0.9.2
[15] markdown_0.7.7 knitr_1.12
loaded via a namespace (and not attached):
[1] zoo_1.7-12 reshape2_1.4.1 splines_3.2.3 colorspace_1.2-6 htmltools_0.3 yaml_2.1.13 gmp_0.5-12 foreign_0.8-66
[9] Rmpfr_0.6-0 plyr_1.8.3 munsell_0.4.2 gtable_0.1.2 leaps_2.9 codetools_0.2-14 evaluate_0.8 labeling_0.3
[17] httpuv_1.3.3 lmtest_0.9-34 vcd_1.4-1 proto_0.3-10 Rcpp_0.12.0 acepack_1.3-3.3 scales_0.3.0 formatR_1.2.1
[25] Hmisc_3.16-0 abind_1.4-3 mime_0.4 digest_0.6.9 stringi_1.0-1 shiny_0.13.0 tools_3.2.3 sandwich_2.3-3
[33] magrittr_1.5 Formula_1.2-1 cluster_2.0.3 MASS_7.3-45 R6_2.1.0 rpart_4.1-10 nnet_7.3-11
As suggested in the comments by CL. and JasonAizkalns, a knitr bug is the issue, so downloading the developmental version of knitr should fix the issue.
update.packages(ask = FALSE, repos = 'http://cran.rstudio.org')
install.packages('knitr', repos = c('http://yihui.name/xran', 'http://cran.rstudio.org'))
OR
devtools::install_github('yihui/knitr', build_vignettes = TRUE)
Also for anyone else facing the same issue who is unable/unwilling to download the developmental version adding cat('\n\n') after the print command is a workaround for the bug!
i.e.
for(v in Values){
print(ggplot(mtcars, aes(x=carb, y = v, shape=gear)) + geom_point())
cat('\n\n')
}

GSEA-R error R Mac OSX El Capitan

Not sure how many people still use the R script for GSEA, but when I try and load the script and its functions:
GSEA.program.location <- ("file location of GSEA.1.0.R")
source(GSEA.program.location, verbose=T, max.deparse.length=9999)
I get this error
'envir' chosen:<environment: R_GlobalEnv>
encoding = "native.enc" chosen
Error: '\%' is an unrecognized escape in character string starting ""Tag \%"
I believe I have to remove the backspace, but I have searched through GSEA.1.0.R, and the "source" function source code, and I can't find this '\%'. What is it that I am doing wrong?
Session info:
R version 3.2.2 (2015-08-14)
Platform: x86_64-apple-darwin13.4.0 (64-bit)
Running under: OS X 10.11.1 (El Capitan)
locale:
[1] C/C/C/C/C/en_GB.UTF-8
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] biomaRt_2.26.0 WGCNA_1.48 RSQLite_1.0.0 DBI_0.3.1 fastcluster_1.1.16 dynamicTreeCut_1.62
loaded via a namespace (and not attached):
[1] reshape2_1.4.1 splines_3.2.2 lattice_0.20-33 colorspace_1.2-6 htmltools_0.2.6
[6] stats4_3.2.2 yaml_2.1.13 survival_2.38-3 XML_3.98-1.3 foreign_0.8-66
[11] BiocGenerics_0.16.1 RColorBrewer_1.1-2 matrixStats_0.15.0 foreach_1.4.3 plyr_1.8.3
[16] stringr_1.0.0 munsell_0.4.2 gtable_0.1.2 codetools_0.2-14 latticeExtra_0.6-26
[21] Biobase_2.30.0 IRanges_2.4.1 doParallel_1.0.10 parallel_3.2.2 AnnotationDbi_1.32.0
[26] preprocessCore_1.32.0 GSEABase_1.32.0 proto_0.3-10 Rcpp_0.12.1 acepack_1.3-3.3
[31] xtable_1.8-0 scales_0.3.0 S4Vectors_0.8.1 Hmisc_3.17-0 graph_1.48.0
[36] annotate_1.48.0 gridExtra_2.0.0 impute_1.44.0 ggplot2_1.0.1 digest_0.6.8
[41] stringi_1.0-1 grid_3.2.2 tools_3.2.2 bitops_1.0-6 magrittr_1.5
[46] RCurl_1.95-4.7 Formula_1.2-1 cluster_2.0.3 GO.db_3.2.2 MASS_7.3-45
[51] rmarkdown_0.8.1 iterators_1.0.8 rpart_4.1-10 nnet_7.3-11
These warnings occur when you have R version 2.5 and higher installed. To fix, remove the single backslashes in front of these characters as there is no need to escape them in R versions 2.5 and higher.

Resources