From 9f4ec26e7393eab5f5df55083de6650aaea56b7a Mon Sep 17 00:00:00 2001 From: Edzer Pebesma Date: Wed, 19 Aug 2015 00:00:00 +0000 Subject: [PATCH] version 1.27.1 --- DESCRIPTION | 13 ++++---- MD5 | 26 ++++++++------- R/hdiffplot.R | 2 +- R/hexPlotMA.R | 37 ++++++++++++--------- R/hexViewport.R | 9 +++-- R/lattice.R | 12 +++---- README.md | 5 +++ TODO | 5 +++ build/vignette.rds | Bin 267 -> 267 bytes man/erode.hexbin.Rd | 2 +- man/gplot.hexbin.Rd | 2 +- man/grid.hexagons.Rd | 2 +- tests/hray.Rout.save | 52 +++++++++++++++++++++++++++++ tests/large.Rout.save | 60 ++++++++++++++++++++++++++++++++++ tests/viewp-ex.Rout.save | 42 ++++++++++++++++++++++++ vignettes/hexagon_binning.Rnw | 15 +++++---- 16 files changed, 232 insertions(+), 52 deletions(-) create mode 100644 README.md create mode 100644 tests/hray.Rout.save create mode 100644 tests/large.Rout.save create mode 100644 tests/viewp-ex.Rout.save diff --git a/DESCRIPTION b/DESCRIPTION index 97d9129..8fd91b5 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,15 +1,15 @@ Package: hexbin -Version: 1.27.0 -Date: 2014-08-08 +Version: 1.27.1 +Date: 2015-08-19 Title: Hexagonal Binning Routines Author: Dan Carr , ported by Nicholas Lewin-Koh and Martin Maechler , - contains copies of lattice function written by Deepayan Sarkar + contains copies of lattice functions written by Deepayan Sarkar Maintainer: Edzer Pebesma Depends: R (>= 2.0.1), methods Imports: lattice, grid, graphics, grDevices, stats, utils -Suggests: marray, affy, Biobase +Suggests: marray, affy, Biobase, limma Description: Binning and plotting functions for hexagonal bins. Now uses and relies on grid graphics and formal (S4) classes and methods. @@ -19,6 +19,7 @@ Collate: lattice.R BTC.R BTY.R grid.hexagons.R grid.hexlegend.R hbox.R LOCS.R MAG.R RB.R smoothHexbin.R License: GPL-2 NeedsCompilation: yes -Packaged: 2014-08-09 14:47:07 UTC; edzer +URL: http://github.com/edzer/hexbin +Packaged: 2015-08-19 15:11:53 UTC; edzer Repository: CRAN -Date/Publication: 2014-08-09 16:56:37 +Date/Publication: 2015-08-19 17:28:20 diff --git a/MD5 b/MD5 index 7c3113a..fdd6c73 100644 --- a/MD5 +++ b/MD5 @@ -1,5 +1,5 @@ b8c6e7f6b0230cdf61f0976d387c7a44 *ChangeLog -b66be4500e652afd8a98305a38f240da *DESCRIPTION +58f0420f8288b4faae52aba21669bc3d *DESCRIPTION 9129a733a21f780d50b1c3bb85da0047 *NAMESPACE 98a77d0235bb074f09aa7675358b8650 *R/BTC.R b8083617bec9ef2a20bf2fb31d1f50cb *R/BTY.R @@ -11,29 +11,30 @@ c25363a22b3f824d1f25997179b74434 *R/RB.R 97262cc9f616661bf71e4686225f6c17 *R/grid.hexagons.R cd88d10aa75a6666b296efff0ac1f355 *R/grid.hexlegend.R 503b110bf985d5c12a0d514c333dc81e *R/hbox.R -af47bcebc0383679d4d0698942a6c868 *R/hdiffplot.R -85315d7d03d9e9db93d3a14d62b960af *R/hexPlotMA.R -5728b07de4711701d1b2acf6a9f06fe9 *R/hexViewport.R +ad4a901fb8fc48deb4f76ad3d797ecd9 *R/hdiffplot.R +d53fcb4dabb71c0154e881648c6b13da *R/hexPlotMA.R +e5cb8c5f3ba8f183d4c69e50f153f845 *R/hexViewport.R 48ab7518d22b3310dab41acae327c743 *R/hexbin.s4.R 5d66d35fa92d45957684ee3375513e28 *R/hexbinList.R ae5724baa7c3661621ed0018287fc6ca *R/hexbinplot.R 53e8c6ea014e06b21e56b8e447a0dad5 *R/hexpanel.R 249d47000fdc8b641cf6ed2ee6f640bb *R/hexplom.R 0b7181a5ae4cbc780f46041886fc80e8 *R/hexutil.R -7938c3dc88323c01ff2a2a040d29c19d *R/lattice.R +acf4489ea175f01eb1659a420183e155 *R/lattice.R 449d6bbfb6927f39383b586ffce19eb1 *R/smoothHexbin.R -b943a359274739b935bb5885d733d42d *TODO -2eab3d71f8ccae48cacbc328f428d2bd *build/vignette.rds +408e6e0599f15c991715933ddd85400f *README.md +53e586900ba0c452c12ec7aed3d20295 *TODO +dd1765c586720d0a4c7c5064fce7da74 *build/vignette.rds cfa9343134507d8eaf7386167ea1243d *data/NHANES.rda a6e0f6f67abc1c4d94ad6b2d33860fe2 *inst/doc/hexagon_binning.R ed9dbcabcbb9240445d6dac2de22ba5f *inst/doc/hexagon_binning.Rnw 4550e584d1ad491edcb547bd4ec28845 *inst/doc/hexagon_binning.pdf 3b3cb098160c79abc4d739397d315ff3 *man/NHANES.Rd bfc5169b22c653bb5912e9c3e92f3207 *man/colramp.Rd -428bdc3a94aedc5816d0cbc72e4271d7 *man/erode.hexbin.Rd +94a1639600897389f489b6b836362d82 *man/erode.hexbin.Rd 47a11326b5056014da626fe8c3c5b8e8 *man/getHMedian.Rd -59c3d8f5ac3b772a88e5b0a5c0b96d28 *man/gplot.hexbin.Rd -d342c3bc65cea7fb4b2103dd7bebeabf *man/grid.hexagons.Rd +651ab732e881463b6516824c162e35ac *man/gplot.hexbin.Rd +4f14ff188dcc89ced1434511b0da5dc0 *man/grid.hexagons.Rd 6e12f30832b4d71515a91bb8c448049d *man/grid.hexlegend.Rd 5f2695c8af33d84b154a61e3463859e9 *man/hboxplot.Rd eb4f91c7c9c4482122d7c9ee209e93b6 *man/hcell2xy.Rd @@ -68,6 +69,9 @@ f8fb4b9ec5a1dbc174102d40377ce885 *src/herode.f ddcf0653ed6863dd0260e1f58349356a *tests/hdiffplot.R 66fb0e8391d2b94fbdb2633ac4d70e21 *tests/hdiffplot.Rout.save efe67770786c28cc2bfceef357376f7a *tests/hray.R +24021c6251d46ad71065e3705e04479d *tests/hray.Rout.save 6dca74e0501c54cede56d657a1c0c632 *tests/large.R +98321f01b4ed346aa059aec1aa3c637a *tests/large.Rout.save f94ffad94528308a3483bf6f4088fa70 *tests/viewp-ex.R -049e6d8eb7c68d12f2e78f48b26c84f5 *vignettes/hexagon_binning.Rnw +53478aa4cafb6fb935b12b7c982a667d *tests/viewp-ex.Rout.save +d6c9a9e05a1165a6e0da8b309303082b *vignettes/hexagon_binning.Rnw diff --git a/R/hdiffplot.R b/R/hdiffplot.R index 2943c16..8dcdca4 100644 --- a/R/hdiffplot.R +++ b/R/hdiffplot.R @@ -169,7 +169,7 @@ hdiffplot <- grid.text(xlab, y = unit(-2, "lines"), gp = gpar(fontsize = 16)) if(nchar(ylab) > 0) grid.text(ylab, x = unit(-2, "lines"), gp = gpar(fontsize = 16), rot = 90) - if(nchar(main) > 0) + if(sum(nchar(main)) > 0) grid.text(main, y = unit(1, "npc") + unit(1.5, "lines"), gp = gpar(fontsize = 18)) diff --git a/R/hexPlotMA.R b/R/hexPlotMA.R index 265d564..20ed2ba 100644 --- a/R/hexPlotMA.R +++ b/R/hexPlotMA.R @@ -13,13 +13,17 @@ plotMAhex <- function (MA, array = 1, xlab = "A", ylab = "M", xaxt = c("s", "n"), yaxt = c("s", "n"), verbose = getOption("verbose")) { + if (!requireNamespace("marray", quietly = TRUE)) + stop("cannot process objects without package marray") + if (!requireNamespace("limma", quietly = TRUE)) + stop("cannot process objects without package limma") if(is.null(main))main <- "" switch(class(MA),marrayRaw={ - x <- maA(MA[,array]) - y <- maM(MA[,array]) - w <- maW(MA[,array]) + x <- marray::maA(MA[,array]) + y <- marray::maM(MA[,array]) + w <- marray::maW(MA[,array]) },RGList = { - MA <- MA.RG(MA[, array]) + MA <- limma::MA.RG(MA[, array]) array <- 1 x <- MA$A y <- MA$M @@ -58,33 +62,34 @@ plotMAhex <- function (MA, array = 1, xlab = "A", ylab = "M", y <- MA[, array] - x w <- NULL }, ExpressionSet = { - if(!require(Biobase)) + if (!requireNamespace("Biobase", quietly = TRUE)) stop("cannot process ExpressionSet objects without package Biobase") - narrays <- ncol(exprs(MA)) + narrays <- ncol(Biobase::exprs(MA)) if (narrays < 2) stop("Need at least two arrays") if (narrays > 5) - x <- apply(exprs(MA), 1, median, na.rm = TRUE) + x <- apply(Biobase::exprs(MA), 1, median, na.rm = TRUE) else - x <- rowMeans(exprs(MA), na.rm = TRUE) - y <- exprs(MA)[, array] - x + x <- rowMeans(Biobase::exprs(MA), na.rm = TRUE) + y <- Biobase::exprs(MA)[, array] - x w <- NULL if (missing(main)) - main <- colnames(exprs(MA))[array] + main <- colnames(Biobase::exprs(MA))[array] }, AffyBatch = { - if(!require(affy)| !require(Biobase)) + if (!requireNamespace("Biobase", quietly = TRUE) || + !requireNamespace("affy", quietly = TRUE)) stop("cannot process AffyBatch objects without package Biobase and affy") - narrays <- ncol(exprs(MA)) + narrays <- ncol(Biobase::exprs(MA)) if (narrays < 2) stop("Need at least two arrays") if (narrays > 5) - x <- apply(log2(exprs(MA)), 1, median, na.rm = TRUE) + x <- apply(log2(Biobase::exprs(MA)), 1, median, na.rm = TRUE) else - x <- rowMeans(log2(exprs(MA)), na.rm = TRUE) - y <- log2(exprs(MA)[, array]) - x + x <- rowMeans(log2(Biobase::exprs(MA)), na.rm = TRUE) + y <- log2(Biobase::exprs(MA)[, array]) - x w <- NULL if (missing(main)) - main <- colnames(exprs(MA))[array] + main <- colnames(Biobase::exprs(MA))[array] }, stop("MA is invalid object")) if (!is.null(w) && !zero.weights) { i <- is.na(w) | (w <= 0) diff --git a/R/hexViewport.R b/R/hexViewport.R index 726c522..2adb1b4 100644 --- a/R/hexViewport.R +++ b/R/hexViewport.R @@ -241,9 +241,12 @@ hexVP.loess <- function(hbin, hvp = NULL, span = 0.4, col = 'red', n = 200) fit <- loess(hbin@ycm ~ hbin@xcm, weights = hbin@count, span = span) if(!is.null(hvp)) { pushHexport(hvp, clip = 'on') - grid.lines(seq(0,16, length = n), - predict(fit,seq(0,16, length = n)), - gp = gpar(col = col), default.units = 'native') +# grid.lines(seq(0,16, length = n), +# predict(fit,seq(0,16, length = n)), +# gp = gpar(col = col), default.units = 'native') + grid.lines(seq(hbin@xbnds[1], hbin@xbnds[2], length = n), + predict(fit,seq(hbin@xbnds[1], hbin@xbnds[2], length = n)), + gp = gpar(col = col), default.units = 'native') popViewport() } invisible(fit) diff --git a/R/lattice.R b/R/lattice.R index 2d9b3ce..bfae156 100644 --- a/R/lattice.R +++ b/R/lattice.R @@ -7,12 +7,12 @@ # # checking dependencies in R code ... NOTE # Unexported objects imported by ':::' calls: -# ‘lattice:::cond.orders’ ‘lattice:::construct.scales’ -# ‘lattice:::cupdate’ ‘lattice:::limits.and.aspect’ -# ‘lattice:::trellis.skeleton’ -# See the note in ?`:::` about the use of this operator. -# See the information on DESCRIPTION files in the chapter ‘Creating R -# packages’ of the ‘Writing R Extensions’ manual. +# lattice:::cond.orders lattice:::construct.scales +# lattice:::cupdate lattice:::limits.and.aspect +# lattice:::trellis.skeleton +# See the note in ?::: about the use of this operator. +# See the information on DESCRIPTION files in the chapter Creating R +# packages of the Writing R Extensions manual. # the files in lattice carry the following copyright notice: diff --git a/README.md b/README.md new file mode 100644 index 0000000..d87cb7a --- /dev/null +++ b/README.md @@ -0,0 +1,5 @@ +hexbin +====== +[![Build Status](https://travis-ci.org/edzer/hexbin.png?branch=master)](https://travis-ci.org/edzer/hexbin) + +An R Package with binning and plotting functions for hexagonal bins. diff --git a/TODO b/TODO index aba86e8..eddd7c7 100644 --- a/TODO +++ b/TODO @@ -1,3 +1,8 @@ +-------------- +Aug 10, 2014 +o get rid of functions in lattice.R, which were copied from lattice + +-------------- o The new 3D plots -- should rather make the new functions "internal" and choosable with *arguments* from given functions ! diff --git a/build/vignette.rds b/build/vignette.rds index fe60b6e941763adbc4fd30fa931c3737534c6913..44c1e0f77929f1ff85865be0c87912bda4d085f8 100644 GIT binary patch delta 197 zcmV;$06PDR0*e9^ABzY80000000V`Q;Y!0W5XaMGkrXd~G0p_%j0@U|jFyzd03>S-;NlBz0}s*8}T8;|7I9{DdrQ*I(;dLlxFW#51YMGvL~64Rdsm62t* z*@7{!ry&28_)NhT+eqzvh7GFHg+Kq$8Q;C4$(veR>kRqe;B^AarNE!u!S%612} zdhfFaiJo9-muB delta 197 zcmV;$06PDR0*e9^ABzY80000000V`Q;Y!0W5XX~dkrXd~v4jcESt4jFGFnoa6Plb2 z*pR;23%)_6)zexkB~?`{RTm*wHy+8aJ@Q|Mrrbox^hAUT%f0~*iXKb}B&I(NDkIBq zvjt;dPr>9@;xh$XY$LVv88)a&7ykT1XMFdHCU0tOtuy3 z@*S+y%IotSLnL{zz library(hexbin) +> +> set.seed(572) +> +> x <- rnorm(100) +> y <- rnorm(100) +> val <- rnorm(100) +> inc <- abs(rnorm(100,sd = .3)) +> loB <- val-inc +> hiB <- val+inc +> +> if(exists("hray", mode="function")) { # 'real soon now' ++ ++ ## no confidence bounds ++ plot(x,y,type = 'n') ++ hray(x,y,val) ++ ++ ## confidence bounds ++ plot(x,y,type = 'n') ++ hray(x,y,val, lo = loB, hi = hiB) ++ ++ ## clockwise orientation ++ plot(x,y,type = 'n') ++ hray(x,y,val, loB, hiB, clockwise = TRUE) ++ ++ ## no tics and small filled dots ++ plot(x,y,type = 'n') ++ hray(x,y,val, loB, hiB, ticlength = FALSE, ++ dotside = 20, dotlength = .025, dotden = -1) ++ ++ } +> +> proc.time() + user system elapsed + 0.252 0.012 0.258 diff --git a/tests/large.Rout.save b/tests/large.Rout.save new file mode 100644 index 0000000..5081e01 --- /dev/null +++ b/tests/large.Rout.save @@ -0,0 +1,60 @@ + +R version 3.1.1 (2014-07-10) -- "Sock it to Me" +Copyright (C) 2014 The R Foundation for Statistical Computing +Platform: x86_64-pc-linux-gnu (64-bit) + +R is free software and comes with ABSOLUTELY NO WARRANTY. +You are welcome to redistribute it under certain conditions. +Type 'license()' or 'licence()' for distribution details. + +R is a collaborative project with many contributors. +Type 'contributors()' for more information and +'citation()' on how to cite R or R packages in publications. + +Type 'demo()' for some demos, 'help()' for on-line help, or +'help.start()' for an HTML browser interface to help. +Type 'q()' to quit R. + +> library(hexbin) +> +> if(FALSE) { ## the following is still quite a bit from working/useful : ++ ++ ## what should that do? set a palette? ++ rgb <- matrix(c( ++ 15,15,15, ++ ++ 0, 0, 0, ++ 1, 9,15, ++ 9,15, 9, ++ 15, 9, 9, ++ ++ 0, 0, 0, ++ 0, 0, 0, ++ 0, 0, 0, ++ 0, 0, 0, ++ 0, 0, 0, ++ 0, 0, 0, ++ ++ 9, 9, 9, ++ 0, 2, 7, ++ 0, 7, 1, ++ 8, 1, 1, ++ ++ 15, 2, 2, ++ 11, 1, 1, ++ 8, 1, 1, ++ 5, 1, 1, ++ 5, 1, 1, ++ 15,15,15), ncol = 3, byrow = TRUE) ++ ++ ##ps.options(rasters=600,color=rgb/15,background=2) ++ ##ps.options(color=rgb/15,background=2) ++ postscript("large.ps",width = 10,height = 7.5) ++ ++ plot.hexbin(ans.25mil, style = "nest", lcex = .9) ++ ++ }## FALSE, i.e. nothing done +> +> proc.time() + user system elapsed + 0.240 0.032 0.265 diff --git a/tests/viewp-ex.Rout.save b/tests/viewp-ex.Rout.save new file mode 100644 index 0000000..a2806ca --- /dev/null +++ b/tests/viewp-ex.Rout.save @@ -0,0 +1,42 @@ + +R version 3.1.1 (2014-07-10) -- "Sock it to Me" +Copyright (C) 2014 The R Foundation for Statistical Computing +Platform: x86_64-pc-linux-gnu (64-bit) + +R is free software and comes with ABSOLUTELY NO WARRANTY. +You are welcome to redistribute it under certain conditions. +Type 'license()' or 'licence()' for distribution details. + +R is a collaborative project with many contributors. +Type 'contributors()' for more information and +'citation()' on how to cite R or R packages in publications. + +Type 'demo()' for some demos, 'help()' for on-line help, or +'help.start()' for an HTML browser interface to help. +Type 'q()' to quit R. + +> library(hexbin) +> +> ## a variation on Nicholas' post to bioconductor & example(hexViewport) +> set.seed(545) +> x <- rnorm(2^15) +> y <- 3*x - .2*x^2 + rnorm(2^15) +> hbin <- hexbin(x,y) +> +> ## +> hp <- hexViewport(hbin, newpage = TRUE) +> pushHexport(hp) +> library("grid") +> grid.rect() +> grid.xaxis() +> grid.yaxis() +> grid.hexagons(hbin, style = "centroid") +> hloess <- loess(y ~ x, data = hcell2xy(hbin), weights = hbin @ count) +> xx <- seq(hbin@xbnds[1], hbin@xbnds[2], length = 500) +> grid.lines(xx, predict(hloess, xx), ++ gp = gpar(col = 'red', lwd = 2), default.units = "native") +> popViewport() +> +> proc.time() + user system elapsed + 0.368 0.020 0.379 diff --git a/vignettes/hexagon_binning.Rnw b/vignettes/hexagon_binning.Rnw index fa09734..928a584 100644 --- a/vignettes/hexagon_binning.Rnw +++ b/vignettes/hexagon_binning.Rnw @@ -65,7 +65,7 @@ with squares our eyes are drawn to the horizontal and vertical lines of the grid. The following figure adapted from \cite[]{carretal}shows this effectively. -\begin{figure}[H] +\begin{figure}[h] \centering <>= library("grid") @@ -134,7 +134,7 @@ fc.sq$y <- sqrt(3)*fc.sq$y # stretch y by the sqrt(3) nr <- length(fc.sq$x)/2 @ -\begin{figure}[H] +\begin{figure}[h] \centering << fig = TRUE,width = 4,height = 8,echo = FALSE >>= par(mfrow = c(3,1)) @@ -342,10 +342,10 @@ set NHANES. The data consist of 9575 persons and mesures various clinical factors. Here in Figure~\ref{hbox} we show the levels of transferin, a measure of iron binding against hemoglobin for all -\begin{figure}[H] +\begin{figure}[h] \centering -<< hbox, fig = TRUE, width = 6, height = 4, echo = FALSE >>= +<< echo = FALSE >>= data(NHANES) #grid.newpage() mar <- unit(0.1 + c(5,4,4,2),"lines") @@ -354,6 +354,9 @@ mai <- as.numeric(convertUnit(mar, "inches")) # convertHeight(unit(1,"npc"), "inches")) vpin <- c(unit(6,"inches"),unit(4, "inches")) shape <- optShape(height = vpin[2], width = vpin[1], mar = mai) +@ + +<< hbox, fig = TRUE, width = 6, height = 4, echo = FALSE >>= hb <- hexbin(NHANES$Transferin, NHANES$Hemoglobin, shape = shape) hbhp <- hboxplot(erode(hb,cdfcut = .05),unzoom = 1.3) pushHexport(hbhp,clip = 'on') @@ -382,7 +385,7 @@ of the ability of blood to bind oxygen, vs the level of hemoglobin. Note that in the call to \texttt{hdiffplot} we erode the bins to calculate the bivariate medians, and only display the upper 75\% of the data. -\begin{figure}[H] +\begin{figure}[h] \centering << hdiff, fig = TRUE, width = 6, height = 4, echo = TRUE >>= #grid.newpage() @@ -395,7 +398,7 @@ hbF <- hexbin(NHANES$Transferin[NHANES$Sex == "F"], hbM <- hexbin(NHANES$Transferin[NHANES$Sex == "M"], NHANES$Hemoglobin[NHANES$Sex == "M"], xbnds = xbnds, ybnds = ybnds, shape = shape) -plot.new() +#plot.new() hdiffplot(erode(hbF,cdfcut = .25),erode(hbM,cdfcut = .25),unzoom = 1.3) @ \caption{A difference plot of transferin vs hemoglobin for males and females.}